Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

@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 instantiated with different generic types?

like image 313
Dean J Avatar asked Aug 10 '10 01:08

Dean J


1 Answers

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

public class Gen<T> {
  public static T foo; // compiler error
}
like image 96
cletus Avatar answered Oct 29 '22 20:10

cletus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!