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