我很难找到如何在使用反射时对动态创建的类进行类型转换。
String s;
...
Class unknownClass = Class.forName(s);
Constructor defaultConstructor = unknownClass.getConstructor(null);
Object retobj = defaultConstructor.newInstance(null);
retobj.Writeout(); // This won't work since;
对象类没有称为 Writeout 的方法,但这是由此处动态创建的其他九个可能的类共享的方法的名称(不用说每个 Writeout 方法都做单独的事情)。有什么建议么 ?提前谢谢您的时间。