I am using java 8.
I recently came across this:
public class Test {
public static void main(String[] args) {
String ss = "" + (Test.<Integer>abc(2));
System.out.println(Test.<Integer>abc(2));
}
public static <T> T abc(T a) {
String s = "adsa";
return (T) s;
}
}
This does not throw a java.lang.ClassCastException. Why is that?
I always thought + and System.out.println calls toString. But when I try to do that it throws an Exception as expected.
String sss = (Test.<Integer>abc(2)).toString();