interface I1 { ... }
interface I2 { ... }
interface I3 { ... }
interface I4 { ... }
interface MyFactory {
Object<? extends I1 & I2 & I3> createI1I2I3(); // doesn't work
Object<? extends I2 & I3 & I4> createI2I3I4(); // doesn't work
}
有一招,办呢?我想这样的事情在Java中的接口中使用固定类型约束?
interface I1I2I3 extends I1, I2, I3 { ... }
但I1I2I3
!= <? extends I1 & I2 & I3>
。有一个原因,我不能使用这种方法 - I1
,I2
和I3
是外国的代码。
更新
对于那些谁好奇,为什么会有人需要这样一个奇怪的事情:
interface Clickable {}
interface Moveable {}
interface ThatHasText {}
interface Factory {
Object<? extends Clickable> createButton(); // just a button with no text on it
Object<? extends Clickable & ThatHasText> createButtonWithText();
Object<? extends Moveable & ThatHasText> createAnnoyingBanner();
}
我学习了这样的构造的用例... –
看到我的更新;-) – agibalov