title: Creating a method to check if a value exists in a generic HashMap in Java?
body: <p>I was trying to create a generic method for checking if an item exists within a HashMap. Simple enough concept, but Java does not like what I'm trying to do. Is this even possible? This was my attempt.</p>
  
  <pre><code>private static boolean inMap(String file, HashMap&lt;String, Object&gt; map) {
      for (Map.Entry&lt;String, Object&gt; entry : map.entrySet()) {
          if (entry.getKey().equals(file)) return true;
      }
      return false;
  }
  </code></pre>
  
  <p>This is called in the following section of code:</p>
  
  <pre><code>private static Map&lt;String, String&gt; files = new HashMap();
  private static Map&lt;String, BufferedImage&gt; images = new HashMap();
  private static Map&lt;String, Texture&gt; textures = new HashMap();
  private static Map&lt;String, Model&gt; models = new HashMap();
  
  public static TexturedModel loadOBJModel(String file) {
      if (inMap(file, files)) ...
  }
  
  public static Texture loadTexture(String file) {
      if (inMap(file, textures)) ...
  }
  </code></pre>
  
  <p>I wanted this method to be generic for saving code and simplicity, as i have 4 different HashMaps to check. All of them are <code>String</code> keys, but they are all of different Value types as shown above.</p>
  
  <p>If there is any way to make this generic, any help is welcome!</p>