【发布时间】:2009-05-04 16:56:35
【问题描述】:
我想定义一个接口 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?
}
【问题讨论】: