1. Type variables in the static context of generic classes are invalid.
//静态域或者方法里不能引用类型变量 private static T instance; //静态方法 本身是泛型方法就行 private static <T> T getInstance(){ }
2. Type variables cannot be instantiated.
// public Restrict() { // this.data = new T(); // }
3. Generic parameters cannot be instantiated with basic types.
// NormalGeneric<double> normalGeneric = new NormalGeneric<>(); NormalGeneric<Double> normalGeneric = new NormalGeneric<>();
4. Arrays of parameterized types cannot be created.
Restrict<Double>[] restrictArray; Restrict<Double>[] restricts = new Restrict<Double>[10];
The above is the detailed content of What are the limitations of Java generics?. For more information, please follow other related articles on the PHP Chinese website!