title: Using LambdaMetaFactory to expose getters causes class cast exception
body: <p>I'm using LambdaMetaFactory to expose getters. I have a POJO with many fields and I don't know which fields are going to be populated. I'm trying to avoid both an extended if statement and also reflection.</p>
  <p>So here's a snippet from my POJO:</p>
  <pre><code>@Data
  @Builder
  public class MyPojo {
  
  private String email;
  
  private String firstName;
  
  private String lastName;
  
  private String zipCode;
  
  private String city;
  
  private String street;
  
  private String country;
  
  ...
  
      }
  </code></pre>
  <p>and here's my method which get's my values from all of the getters:</p>
  <pre><code>    public static String getValueFromGetterMethodName(String fieldName, MyPojo myPojo) {
  
      String methodName = constructGetterMethodName(fieldName);
      final MethodHandles.Lookup lookup = MethodHandles.lookup();
      MethodType getChangeDataMethodType = methodType(String.class, MyPojo.class);
  
      try {
          final CallSite site = LambdaMetafactory.metafactory(lookup, &quot;apply&quot;, methodType(Function.class),
                  methodType(Object.class, Object.class),
                  lookup.findVirtual(MyPojo.class, methodName, methodType(String.class)),
                  getChangeDataMethodType);
  
          Function&lt;MyPojo, String&gt; getterFunction = (Function&lt;MyPojo, String&gt;) site.getTarget()
                  .invokeExact();
          return getterFunction.apply(myPojo);
      }
      catch (Throwable e) {
          log.error(&quot;Error getting getter method ref: &quot; + e.getMessage());
          e.printStackTrace();
      }
  
      return null;
  }
  </code></pre>
  <p>The problem is that this line here:</p>
  <pre><code> Function&lt;MyPojo, String&gt; getterFunction = (Function&lt;MyPojo, String&gt;) site.getTarget()
                  .invokeExact();
  </code></pre>
  <p>produces an Unchecked Class Cast warning. I know we're supposed to avoid those. This code works quite well. I'm not sure how to change it to avoid the class cast exception. CallSite doesn't accept parameters.</p>