Can I add to a generic collection of type A values of type B ,which extends A, without any special syntax?

前端 未结 3 1304
感情败类
感情败类 2021-01-22 10:06
public class Stack {
    public Stack () {....}
    public void push (E e) {....}
    public E pop () {....}
    public boolean isEmpty(){....}
}

public void p         


        
3条回答
  •  逝去的感伤
    2021-01-22 10:37

    This problem is due the fact that collections in java are not covariant. There are numerous question on SO about it, such as this one.

提交回复
热议问题