18 lines
548 B
Java
18 lines
548 B
Java
//: typeinfo/toys/GenericToyTest.java
|
|
// ©2015 MindView LLC: see Copyright.txt
|
|
// 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();
|
|
}
|
|
} ///:~
|