我想定義一個接口MyList,它是接口MyThing的列表。 MyList的部分語義是它的操作對沒有實現MyThing接口的對象沒有任何意義。通用接口:具體內容列表
這是正確的聲明嗎?
interface MyList<E extends MyThing> extends List<E> { ... }
編輯:(部分2)現在我有一個返回MYLIST作爲其方法之一,另一個接口。
// I'm defining this interface
// it looks like it needs a wildcard or template parameter
interface MyPlace {
MyList getThings();
}
// A sample implementation of this interface
class SpecificPlace<E extends MyThing> implements MyPlace {
MyList<E> getThings();
}
// maybe someone else wants to do the following
// it's a class that is specific to a MyNeatThing which is
// a subclass of MyThing
class SuperNeatoPlace<E extends MyNeatThing> implements MyPlace {
MyList<E> getThings();
// problem?
// this E makes the getThings() signature different, doesn't it?
}
嘿等一下,剛剛發生的事情與名單是消費者,我們應該使用超級? – willcodejavaforfood 2009-05-04 17:05:16
你不能在class類型參數聲明中使用super,這使我無需找出答案。 ;) – 2009-05-04 17:07:53