使双消费者接受对象
2022-09-04 21:21:12
我有一个JTable TableModel的列定义列表,其中列“B”有一个setter BiConsumer,它接受BauwerkOption类和一个字符串。
当我尝试将字符串设置为带有“...接受...”我收到以下错误:
The method accept(Selektierung.BauwerkOption, capture#4-of ? extends Object) in the type BiConsumer<Selektierung.BauwerkOption,capture#4-of ? extends Object> is not applicable for the arguments (Selektierung.BauwerkOption, Object)
我的代码有什么问题?我甚至有可能想做什么吗?
public class TableModelSelektierung extends DefaultTableModel {
private static final long serialVersionUID = -5921626198599251183L;
private List<BauwerkOption> data;
private static List<ColDef<BauwerkOption, ? extends Object>> DEF = new ArrayList<>();
static {
DEF.add(new ColDef<BauwerkOption, String>("A", (o) -> o.getBauwerkstyp()));
DEF.add(new ColDef<BauwerkOption, String>("B", (o) -> o.getBezeichnung())
.withSetValueAtFunction((i, o) -> i.setBauwerkstyp(o)));
DEF.add(new ColDef<BauwerkOption, String>("C", (o) -> o.getNutzungsart()));
DEF.add(new ColDef<BauwerkOption, Double>("D", (o) -> o.getDurchmesser()));
}
@Override
public int getColumnCount() {
return DEF.size();
}
@Override
public boolean isCellEditable(int row, int column) {
return DEF.get(row).getValueSetterFunction() == null;
}
@Override
public int getRowCount() {
if (data != null) {
return data.size();
}
return 0;
}
@Override
public String getColumnName(int column) {
return DEF.get(column).getTitle();
}
public void setData(List<BauwerkOption> data) {
this.data = data;
fireTableDataChanged();
}
public BauwerkOption getObjectAt(int row) {
return data.get(row);
}
@Override
public void setValueAt(Object aValue, int row, int column) {
if (DEF.get(column).getValueSetterFunction() != null) {
DEF.get(column).getValueSetterFunction().accept(getObjectAt(row), aValue);
}
}
@Override
public Object getValueAt(int row, int column) {
BauwerkOption o = getObjectAt(row);
return DEF.get(column).getValueGetterFunction().apply(o);
}
}
class ColDef<InputObjekt, OutputValue> {
private String title;
private Function<InputObjekt, OutputValue> valueGetterFunction;
private BiConsumer<InputObjekt, OutputValue> valueSetterFunction;
public ColDef(String title, Function<InputObjekt, OutputValue> valueGetterFunction) {
this.title = title;
this.valueGetterFunction = valueGetterFunction;
}
public ColDef<InputObjekt, OutputValue> withSetValueAtFunction(BiConsumer<InputObjekt, OutputValue> valueSetterFunction) {
this.valueSetterFunction = valueSetterFunction;
return this;
}
public Function<InputObjekt, OutputValue> getValueGetterFunction() {
return valueGetterFunction;
}
public String getTitle() {
return title;
}
public BiConsumer<InputObjekt, OutputValue> getValueSetterFunction() {
return valueSetterFunction;
}
}
class BauwerkOption {
public BauwerkOption() {
}
public String getBezeichnung() {
return "";
}
public String getBauwerkstyp() {
return "";
}
public Double getDurchmesser() {
return 0d;
}
public String getNutzungsart() {
return "todo";
}
public void setBauwerkstyp(String s) {
}
}