
1.泛型類別的靜態上下文中類型變數失效。
//靜態域或方法裡不能引用型別變數 private static T instance;
//靜態方法 本身就是泛型方法就行 private static <T> T getInstance(){
} 2、不能實例化類型變數。
// public Restrict() {
// this.data = new T();
// } 3.不能用基本型別實例化泛型參數。
// NormalGeneric<double> normalGeneric = new NormalGeneric<>(); NormalGeneric<Double> normalGeneric = new NormalGeneric<>();
4.不能創建參數化類型的陣列。
Restrict<Double>[] restrictArray; Restrict<Double>[] restricts = new Restrict<Double>[10];
以上就是java泛型的限制探究,希望對大家有幫助。