title: Java: How can I "store" a getter in a variable?
body: <p>I have the following scenario: I have a class:</p>
  <pre><code>public class A {
    
    private B b;
    private C c;
    private D d;
    .
    .
    .
  }
  </code></pre>
  <p>Each of those classes which are fields of class A has (among others) a method which returns a string.</p>
  <pre><code>public class B {
    
    private String name;
  
    public String getName(){
      return name;
    }
    .
    .
    .
  
  }
  </code></pre>
  <p>In my UI there is a data view which displays instances of class A. I would like to make it possible for the user to choose what this overview displays. Ex they want to see the value of C instead of D.</p>
  <p>Now I could just hack this together with if-else statements but there must be a better way to do this. What I'd like to do is simply be able to store a variable which then tells my view which method provides the value to display. How would I do that? When googling I found a couple examples using <code>Supplier</code> however this (as far as I understood) can only be used for specific instances of a class.</p>