Skip to content

Instantly share code, notes, and snippets.

@wfwei
Last active December 14, 2015 02:19
Show Gist options
  • Select an option

  • Save wfwei/5012660 to your computer and use it in GitHub Desktop.

Select an option

Save wfwei/5012660 to your computer and use it in GitHub Desktop.
Java generic based on erasure, so only Object are available at runtime
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