public class Stack {
public Stack () {....}
public void push (E e) {....}
public E pop () {....}
public boolean isEmpty(){....}
}
public void p
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.
the problem is that you have two types but only one generic representation (E) so E is Number as well as Integer. Thats confusing him. You need to have the same type for the collection. Rewrite it to
pushAll(Collection<K> src)
and cast K to E.
Your code specified that it only accepts a Collection
with the same type parameter as the Stack
has.
You should write the pushAll
method like this:
public void pushAll (Collection<? extends E> src)
This means that you expect a Collection
of some type that extends E
(i.e. you don't care what specific type it is, but it must be E
or some sub-type of it).
Look at the definition of Collection.addAll(): it's defined in the same way.