why cant we have primitive types in generixs code example
Example: why cant we have primitive types in generixs
//In java generics are implemented by using "Type erasure" for backward compatibility. All generic types are converted to Object at runtime. for example,
public class Container<T> {
private T data;
public T getData() {
return data;
}
}
//will be seen at runtime as,
public class Container {
private Object data;
public Object getData() {
return data;
}
}
//Compile ensures cast conversion safety