Last active
December 14, 2015 02:19
-
-
Save wfwei/5012660 to your computer and use it in GitHub Desktop.
Java generic based on erasure, so only Object are available at runtime
This file contains hidden or 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
| class Father {} | |
| class Child extends Father {} | |
| public class Test { | |
| public static void main(String args[]){ | |
| Class<Child> cClass = Child.class; | |
| Class<? super Child> fClass = cClass.getSuperclass(); | |
| // This won't compile | |
| // Class<Father> father = fClass.newInstance(); | |
| //only produces Object: | |
| Object obj = fClass.newInstance(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment