我正在尝试Java接口,以下代码给出了错误.
在类中,构造函数将Map作为参数
public class ClassA{
private Map<String,InterfaceA> testMap;
ClassA(Map<String,InterfaceA> testMap){
this.testMap=testMap;
}
}
public class ClassB{
ClassA testA = new ClassA(new HashMap<String,ImplmntsInterfaceA>); //1st declaration
Map<String,ImplmntsInterfaceA> testMap=new HashMap<String,ImplmntsInterfaceA>(); //Second declaration
ClassA testB = new ClassA(testMap);
}
Run Code Online (Sandbox Code Playgroud)
ImplmntsInterfaceA是一个实现的类InterfaceA.
这两个ClassA声明都给出了错误,首先建议将Map构造函数更改为,HashMap然后再次要求将InterfaceA泛型替换为ImplmntsInterfaceA.
有人可以帮忙解决它为什么不起作用?
谢谢 :)