class Gen<T>
{
T val;
Gen(T ob)
{
val=ob;
}
T getOb()
{
System.out.println(val.getClass().getName());
return val;
}
}
Now suppose in the main method if we do following:
Gen<Float> a=new Gen(2.5);
a.getOb()
I get output as
java.lang.Double
Exception in thread "main" java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Float
If "java.lang.Double" is printed it means T was replaced with Double, but we say it should have been replaced with raw type i.e. Object?
What is the reason of this runtime exception?
Please help me in digesting this.