I'm having an issue with some code that I wrote. It compiles fine on my Mac (using "Java 8 Update 121 build 1.8.0", Nano text editor, and just the Java command line compiler javac and java), but it for some reason won't compile on another machine.
On the other machine, the issue stems from the following lines:
public class SomeClass {
...
public static HashMap<String, ArrayList<HashSet<String>>> conversationRecord = new HashMap<>();
...
public static someMethod() {
...
//This produces errors
conversationRecord.put(uuid, new ArrayList<>());
conversationRecord.get(uuid).add(0, new HashSet<>());
conversationRecord.get(uuid).add(1, new HashSet<>());
}//end method
}//end class
java:279: error: no suitable method found for put(String,ArrayList<Object>)
conversationRecord.put(uuid, new ArrayList<>());
^
method HashMap.put(String,ArrayList<HashSet<String>>) is not applicable
(actual argument ArrayList<Object> cannot be converted to ArrayList<HashSet<String>> by method invocation conversion)
method AbstractMap.put(String,ArrayList<HashSet<String>>) is not applicable
(actual argument ArrayList<Object> cannot be converted to ArrayList<HashSet<String>>
It seems like about type inference situation .the jdk8 allow following code:
conversationRecord.put(uuid, new ArrayList<>());
But on earlier version,even jdk7,above code is not allow.so you should check another machine is jdk8 or latter.
Of course,you can change your code like this:
ArrayList<HashSet<String>> temp=new ArrayList<>();
conversationRecord.put(uuid, temp);
For more information about type inference .