OnJava8-Examples/typeinfo/toys/GenericToyTest.java

18 lines
521 B
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// typeinfo/toys/GenericToyTest.java
2015-06-15 17:47:35 -07:00
// Testing class Class.
package typeinfo.toys;
public class GenericToyTest {
public static void main(String[] args) throws Exception {
Class<FancyToy> ftClass = FancyToy.class;
// Produces exact type:
FancyToy fancyToy = ftClass.newInstance();
Class<? super FancyToy> up = ftClass.getSuperclass();
// This won't compile:
// Class<Toy> up2 = ftClass.getSuperclass();
// Only produces Object:
Object obj = up.newInstance();
}
2015-09-07 11:44:36 -06:00
}
/* Output: (None) */