Declaring static generic variables in a generic class

前端 未结 4 635
难免孤独
难免孤独 2021-02-13 13:43

I\'ve read that you cannot declare static variables/methods inside a generic class and I really have no idea how to solve my problem or work around it so I ask for your guidance

4条回答
  •  眼角桃花
    2021-02-13 14:09

    Java generics are quite different than C# generics. There is type erasure, so you can't say something like Nexus.aStaticPublicField (as in C#). You can only say Nexus.aStaticPublicField. There is no way to know what the generic type is (as you don't have an instance), so therefore you can't have a static field of type T.

提交回复
热议问题