0
 Gen<Integer> y=new Gen(2); // Line1
 Integer x=y.getOb(); //Line 2
 Gen<Integer> y1=new Gen<>(2); // Line3
 Integer x1=y1.getOb();//Line4

class Gen<T>
{
    T val;
    Gen(T ob)
    {
       val=ob;
    }
    T getOb()
    {
        return val;
    }

}

I am not able to find any difference between y and y1 objects. Please help me in understanding this.

FYI- It is getting compiled and giving right output.

Rishab Shinghal
  • 591
  • 3
  • 16
  • In the post shared,by you, correct solution has not been explained. – Rishab Shinghal Feb 17 '18 at 07:54
  • 1
    At run time there is no difference between the two due to type erasure (read about how generics are implemented in Java). At compile time `new Gen(2)` has a raw type, while `new Gen<>(2)` has type `Gen` due to type inference. – Henry Feb 17 '18 at 07:57

0 Answers0