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