I'm trying to figure out the whole Java generics topic.
More specifically this issue:
public class Node<E>{
private E data;
public Node(E data){
this.data=data;
}
public E get(){
return this.data;
}
public void set(E data){
this.data=data;
}
}
How can I add an "extends" wildcard specifying that the set method can receive E or any inheriting class of E (in which case the Node will hold a upcasted version of the parameter).
Or will it work even if I leave it the way it is?
(I might be a bit confused with the invariant aspect of generic types.)
Thanks!