📜  为什么我们不能在泛型中使用原始类型 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:28.686000             🧑  作者: Mango

代码示例1
//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 {

    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