1. Type variables in the static context of generic classes are invalid.
//Type variables cannot be referenced in static fields or methods private static T instance; //The static method itself is a generic method. 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>[] restrictions = new Restrict<Double>[10];
The above is an exploration of the limitations of Java generics. I hope it will be helpful to everyone.