title: How to pass in any Object type into a method? Java
body: <p>Note: the NPE error has been fixed</p>
  
  <p>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.</p>
  
  <p>In TOES.java:</p>
  
  <pre><code>import java.util.HashMap;
  
  public class TOES{
  
      private HashMap&lt;Object, HashMap&lt;String, Object&gt;&gt; TOES = new HashMap&lt;Object, HashMap&lt;String, Object&gt;&gt;();
  
      public void add(Object foot, String tag, Object data){
          HashMap&lt;String, Object&gt; TOE = TOES.get(foot);
                  if(TOE == null){
                           TOE = new HashMap&lt;String, Object&gt;;
                   }
          TOE.put(tag, data);
          TOES.put(foot, TOE);
      }
  
      public Object val(Object foot, String tag){
          return TOES.get(foot).get(tag);
      }
  
  }
  </code></pre>
  
  <p>In TOESTest1.java:</p>
  
  <pre><code>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"));
      }
  
  }
  </code></pre>
  
  <p>When TOESTest1 is run, it shows an error for the last println and the return in the val method.</p>
  
  <p>The output should be:</p>
  
  <pre><code>3
  7
  </code></pre>
  
  <p>(Ignore the weird names, TOES is an acronym)</p>
  
  <p>I am new to java, but not new to programming (I know C++), so...</p>