Simple class:
class Box<T> {
private T t;
public Box(T t) {
this.t = t;
}
public void put(T t) {
this.t = t;
}
}
trying to execute put() method passing an instance of Object
Box<?> box = new Box<String>("abc");
box.put(new Object());
Compiler points out an error:
The method put(capture#1-of ?) in the type Box<capture#1-of ?> is not applicable for the arguments (Object)
Compiler in fact does not know what type to expect, but one thing is sure - it will be an Object or a subclass of it. Why is the error raised then?
thank you