Java: Experimenting with generics
Lastly I experimenting with generics a little bit. I came up with this
piece of code:
public class Test {
static <T> void f(T x) {
x = (T) (Integer) 1234;
System.out.println(x);
}
public static void main(String[] args) {
f("a");
f(1);
f('a');
f(1.5);
f(new LinkedList<String>());
f(new HashMap<String, String>());
}
}
I ran this and got this output:
1234
1234
1234
1234
1234
1234
with no exceptions! How is it possible?
No comments:
Post a Comment