我有一对彼此相关的课程:
Msg1 <-> Data1
Msg2 <-> Data2
...
所有“DataX”都扩展了超类“Data”,“MsgX”扩展了类“Msg”。这些超类目前(已简化):
abstract class Data< MSG extends Msg<? extends Data<MSG>>> {
MSG msg;
void modify( MSG msg ) {
this.msg = msg;
};
}
和:
abstract class Msg< DATA extends Data<? extends Msg<DATA>>> {
abstract DATA createData();
void modifyData( DATA data ) {
data.modify( this );
};
}
但是,这两个类 Data 和 Msg 的编译失败,语句“data.modify(this);”出现以下错误:
Msg.java:5: error: method modify in class Data<MSG> cannot be applied to given types;
data.modify( this );
^
required: CAP#1
found: Msg<DATA>
reason: argument mismatch; Msg<DATA> cannot be converted to CAP#1
where DATA,MSG are type-variables:
DATA extends Data<? extends Msg<DATA>> declared in class Msg
MSG extends Msg<? extends Data<MSG>> declared in class Data
where CAP#1 is a fresh type-variable:
CAP#1 extends Msg<DATA> from capture of ? extends Msg<DATA>
1 error
有什么建议吗?我已经尝试了十分之一的变体,添加和删除“?”,“扩展”,......但他们都以某种方式失败了。
慕雪6442864
相关分类