关于类之间参数传递的问题 菜鸟请教大家
我有两个类
第一个类里面有两个Sphere结构的参数 这两个参数将要传到第二个类里面去做运算
第一个类用class.forName和newInstance 来自动创建第二个类的实例 然后调用第二个类里面的processFrame方法
class TestFramework { .......... main() private static Sphere[] spheres; private static Sphere[] spheresBackup; String submissionName = args[0]; Submission student = (Submission)Class.forName(submissionName).newInstance(); .......... int[] studentResult = student.processFrame(x,y,z);interface Submission { public int[] processFrame (double x,double y,double z) throws Exception;}class mySubmission implements Submission { //这里的构造方法应该怎样写才能获得TestFramework这个类的参数???? public int[] processFrame( final double x,final double y,final double z) throws Exception { } }Class class = Class.forName(submissionName);Constructor[] cons = class.getDeclaredConstructors();if(cons[0].getParameterTypes().length>0){ student = (Submission)cons[0].newInstance(new Object[]{new Integer(100),new Integer(200)});}
[解决办法]