Why Java generic classes can't hold static generic variables

as follows, there will be compilation errors. What is the purpose of this design?

public class GenericTest<AnyType> {
    private static AnyType storedValue;//

    public static AnyType read(){//
        return storedValue;
    }
}
Mar.02,2021

static variable can only have one copy in a class, how can it have different types?


GenericTest < String > and GenericTest < Integer > are GenericTest classes after generics are erased, and this class has only one storedValue, that will be ambiguous if generics are allowed.

Menu