Java Generics static type parameter

Question

What is the output of the following code?

class Gen<T> {  
  static T ob;  //from w w w  . j ava 2s . co m
  Gen() {  

    System.out.println(ob);
  }  
} 

public class Main{
  public static void main() {
    Gen<String> g = new Gen<>();
    Gen<Integer> g2 = new Gen<>();
  }
}


Compile time error
Cannot make a static reference to the non-static type T

Note

No static member can use a type parameter declared by the enclosing class.




PreviousNext

Related