Generics

Generics

public class A {
  int i;
  int j;
  void funA()
  {
    i = i+1;
    System.out.println(i);
    j = j+1;
    System.out.println(j);
  }
}

......................................................................

public class Demo<G> {
  G x;
  public static void main(String[] args) {

  Demo<A> d3 = new Demo<A>();
  try
  {
    d3.x.i = 5;//why Null pointer Exception
  }
  catch (Exception e) {
    e.printStackTrace();
  }
 }
}
View Answers

Ads









Related Tutorials/Questions & Answers:
eraser type generics in java
eraser type generics in java  Explain eraser type generics in java with example
Generics
Advertisements
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Generics
Why Generics was introduced in Java?
Why Generics was introduced in Java?  Hi, Why Generics was introduced in Java and what is was its motive? Thanks   Generics were... for compile time type checking. Read the tutorial for more details of Generics

Ads