Why do I get a compiler error in this code ? How do I fix it ?
public class Container<T> {
private T content;
private T defaultValue;
public <T> Container(T defaultValue){
//Compiler error - incompatible types: T cannot be converted to T.
this.defaultValue = defaultValue;
}
}
After type erasure, T defaultValue would become Object defaultValue. Then why can't we assign T defaultValue to Object defaultValue ? After all, every type in Java is an Object.