我有两个班子:乌博伊和唐纳 Obj
public class UpObj {
public UpObj() {
System.out.println("Load UpObj ");
}
}
public class DownObj extends UpObj {
public DownObj() {
System.out.println("Load DownObj ");
}
}
public class Caller {
UpObj obj;
public Caller(UpObj obj) {
this.obj = obj;
System.out.println("!!!");
}
}
public class GNUMakeFile {
/**
* @param args
*/
public static void main(String[] args) {
DownObj iView = new DownObj();
Class<?> iViewClass = iView.getClass();
Class<?> clazz;
try {
clazz = Class.forName("bla.bla.bla.Caller");
Constructor<?> ctor = clazz.getDeclaredConstructor(iViewClass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
}
So, I want upcast my child type DownObj to parent UpObj in Caller constructor. I think this is possible with help generics. Something like this . Anybody know how exactly this use.
感谢。