Are static members of a generic class different for different types in Java?

前端 未结 2 1813
暖寄归人
暖寄归人 2021-01-05 19:07

@Spence asked this Previous Question.

So, how\'s that work in Java? Generic types are discarded at runtime in Java, so what happens to static variables of classes

2条回答
  •  时光说笑
    2021-01-05 19:18

    Static members in Java can't have generic type arguments from the class that contains them.

    public class Gen {
      public static T foo; // compiler error
    }
    

提交回复
热议问题