Created
February 7, 2012 16:23
-
-
Save nicholashagen/1760526 to your computer and use it in GitHub Desktop.
Java Type Erasure Demonstration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TEST 1: what happens in this scenario? | |
List<String> test1 = new ArrayList<String>(); | |
test1.add(new Integer(5)); | |
// TEST 2: what happens and/or is printed in this scenario? | |
List<String> test2 = new ArrayList<String>(); | |
Method method2 = | |
test2.getClass().getMethod("add", String.class); | |
System.out.println(method2); | |
// TEST 3: what happens in this scenario? | |
List<String> test3 = new ArrayList<String>(); | |
Method method3 = | |
test3.getClass().getMethod("add", Object.class); | |
method3.invoke(test3, new Integer(5)); | |
// TEST 4: what happens or is printed in this scenario | |
String result3 = test3.get(0); | |
System.out.println("RESULT 3: " + result3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment