Java Generics casts strangely : <p>I am using java 8.</p>

<p>I recently came across this:</p>

<pre><code>public class Test {
    public static void main(String[] args) {
        String ss = "" + (Test.&lt;Integer&gt;abc(2));
        System.out.println(Test.&lt;Integer&gt;abc(2));
    }
    public static &lt;T&gt; T abc(T a) {
        String s = "adsa";
        return (T) s;
    }
}
</code></pre>

<p>This does not throw a java.lang.ClassCastException. Why is that?</p>

<p>I always thought <code>+</code> and <code>System.out.println</code> calls <code>toString</code>. But when I try to do that it throws an Exception as expected.</p>

<pre><code>String sss = (Test.&lt;Integer&gt;abc(2)).toString();
</code></pre>
