可以吗?(请记住,我没有编写类的主体,也没有编写接口;-))
abstract class SuperClass implements SuperInterface
class SubClass extends SuperClass implements SubInterface
还是一般认为这是不良做法?
让我感到奇怪的是,以下这些无效:
List<SubInterface> myList;
...
for(SuperInterface si : myList) {
...
}
既不是好事也不是坏事。SubClass
这里实现了SuperInterface
和SubInterface
(以及由SuperClass
public方法定义的接口)。如果那是您的需要-很好。
至于你的第二个例子
List<SubInterface> myList;
...
for(SuperInterface si : myList) {
...
}
您声明了SubInterface
元素列表,但想从中获取SuperInterface
元素。如果SubInterface
扩展,SuperInterface
那么这有一定意义。否则不行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句