Note: the NPE error has been fixed
I need a way to identify an Object when it is passed into a method. It can be by name or anything else unique to the Object, but not by type or value, since there may be other Objects with the same type or value in the HashMap.
In TOES.java:
import java.util.HashMap;
public class TOES{
private HashMap<Object, HashMap<String, Object>> TOES = new HashMap<Object, HashMap<String, Object>>();
public void add(Object foot, String tag, Object data){
HashMap<String, Object> TOE = TOES.get(foot);
if(TOE == null){
TOE = new HashMap<String, Object>;
}
TOE.put(tag, data);
TOES.put(foot, TOE);
}
public Object val(Object foot, String tag){
return TOES.get(foot).get(tag);
}
}
In TOESTest1.java:
public class TOESTest1{
public static void main(String[] arg){
TOES Toes = new TOES();
Integer potatoes = 5;
Integer eyes = 7;
String tagname = "eyes";
Toes.add(potatoes,tagname,eyes);
potatoes = 3;
System.out.println(potatoes);
System.out.println(Toes.val(potatoes, "eyes"));
}
}
When TOESTest1 is run, it shows an error for the last println and the return in the val method.
The output should be:
3
7
(Ignore the weird names, TOES is an acronym)
I am new to java, but not new to programming (I know C++), so...