我想定义一个接口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