What's the proper way of setting temp2.in
in the below snippet? Why does the code not compile?
public class WildCards {
public static void main(String[] args) {
TheBox<Integer> temp1 = new TheBox<Integer>();
temp1.set(10);
TheBox<? extends Number> temp2 = temp1;
temp2.set(1);
}
public static class TheBox<T> {
T in;
public T get() {
return in;
}
public void set(T in) {
this.in = in;
}
}
}