无法找到与我完全相同的问题/问题,我试图将类作为接口传递给实现相同接口的另一个类,参见下面的代码:
public class Combiner implements myInterface {
private final myInterface right;
private final myInterface left;
public Combiner(myInterface right, myInterface left) {
this.right = right;
this.left = left;
System.out.println("In constructor");
}来自另一班:
try {
MyInterface right = mine1.class.newInstance();
MYInterface left = mine2.class.newInstance();
Combiner comb = new Combiner(right, left);
} catch (Exception e) {
System.err.println(e);
} mine1:
public class mine1 implements MyInterface { .... }mine2:
public class mine2 implements MyInterface { ..... }MyInterface:
public interface MyInterface { }获取: com.livingcode.workflow.parts.HotspotSelectionChoice : java.lang.InstantiationException:
有什么想法吗,到底有什么不对?
发布于 2015-11-04 09:53:33
mine1.class.newInstance();这是完全没有必要的,你需要实例然后
MyInterface right = new mine1();
MYInterface left = new mine2();
Combiner comb = new Combiner(right, left);注意,Java类名以大写字母开头。
https://stackoverflow.com/questions/33518599
复制相似问题