public class Stack {
private LinkedList<? extends Number> stack;
public <T extends Number> void push(T t){
stack.add(t);
}
public <T extends Number>T pop(){
return stack.removeLast();
}
}
Both add and remove last method are giving compile time error. Please help me to understand what I'm doing wrong here?
Error at push -
The method add(capture#1-of ? extends Number) in the type LinkedList is not applicable for the arguments (T)
Error at pop -
Type mismatch: cannot convert from capture#2-of ? extends Number to T