I've encountered a behaviour of generics in Java that I completely can't understand (with my .NET background).
public class TestGeneric<T>
{
public void get (Object arg)
{
T temp = (T) arg;
System.out.println(temp.toString());
return;
}
}
TestGeneric<Integer> tg = new TestGeneric<Integer>();
tg.get("Crack!!!");
Please tell me why I'm not getting ClassCastException in get, moreover, in Idea I see temp as String
after assignment and having value of "Crack!!!"
. Also, how could I have that ClassCastException throwed? I'm using JDK 1.7.0_07 on Windows 7 x64.