title: Java 8 - Map between class to one of its function
body: <p>I have multiple types of objects, I'd like to generalise the 'id' of the objects in a way that will dynamically change what field is selected as the id. </p>
  
  <p>Example</p>
  
  <pre><code>public class ObjectA{
    //Attribute name attA
    private String attA;
    .... More attributes
    public String getAttA(){
        return attA
    }
  
    .....More getters/setters
  }
  public class ObjectB{
    //Attribute named attB
    private String attB;
    .... More attributes
    public String getAttB(){
        return attB
    }
  
    .... More getters and setters
  }
  </code></pre>
  
  <p>Id like to be able to run something like this:</p>
  
  <pre><code>Map&lt;????, ????&gt; customIdMap = new HashMap&lt;&gt;();
  //We decide that ObjectA main attribute is AttA
  customIdMap.add(ObjectA.class, ObjectA::getAttA);
  //We decide that ObjectB main attribute is AttB
  customIdMap.add(ObjectB.class, ObjectB::getAttB);
  </code></pre>
  
  <p>Then I'll be able to have a list of general objects and ill be able to retrieve their ids from the map if it is a known object with:</p>
  
  <pre><code>public String getCustomId(Object object){
     if(customIdMap.contains(object.getClass()){
        //Parameters are messed up, but this is the general idea of how 
        //i thought this would look
        return customIdMap.get(object.getClass()).apply(object);
     }
  }
  </code></pre>
  
  <p>The code above does not run since getAttA is a call to a none static method in a static context so i assume this maybe should be wrapped in some kind of generic object.</p>
  
  <p>Can it be done?</p>