Having the below code:
Stack<Integer> integers = new Stack<Integer>();
Stack<? extends Number> numbers = integers;
Number n = numbers.pop();
numbers.push(3);
numbers.push(n);
I get compilation errors on the last two lines, but although I've given it some thought I don't understand why the compilation errors are there.
The method push(capture#2-of ? extends Number) in the type Stack<capture#2-of ? extends Number> is not applicable for the arguments (int)
When I comment the last line, I still get the above compilation error, but from my understanding the compiler should be able to infer the correct type (Stack) from those lines.
Thanks a lot