public Class Test{
HashMap<String, HashMap<String, String>> GlobalMap = new HashMap();
private String X;
public static void main(String[] args){
Test t1 = new Test();
t1.read(someTreeObject);
}
@Override
public Void method1(someCtx) {
String A = "some value";
String B = "some other value";
Map Map1 = new HashMap();
Map1.put(A,B);
System.out.println("Local Map : "+Map1.entrySet);
GlobalMap.put(X, (HashMap<String, String>)GlobalMap.get(X).putAll(Map1)); //<<<Compile time error details with the indicator pointing at Map1 within this line: error: incompatible types: void cannot be converted to HashMap<String,String>
// GlobalMap.put(X, (HashMap<String, String>)GlobalMap.get(X).put(new HashMap(A,B))); //<<<<<<<<<This is another approach, when tried gives a compile time error with the indicator pointing at A within this line: error: incompatible types: String cannot be converted to int
System.out.println("Global Map Details : \n"+GlobalMap.entrySet()+"\n");
}
return super.SomeMethod(someCtx);
}
Method1是一個重寫的方法,最初可用於抽象接口。 我知道我沒有想要發送給主要方法。參數化HashMaps:編譯時錯誤:不兼容類型
爲什麼putAll和put方法產生不同的錯誤信息? 我在這裏錯過了什麼?
我是編程和Java新手,真的想學習構建高級HashMaps。在我的經驗中早些時候使用泛型HashMap構造時,我沒有遇到類似於這個錯誤的任何東西。
是的,[putAll](https://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html#putAll(java.util.Map))會返回void –