title: Java8 retrieving lambda setter from class
body: <p>I'm trying to get a lambda method handle for the setter of a private field, but for some reason, the setter cannot be found.</p>
  
  <p>This is the functional interface I am using:</p>
  
  <pre><code>@FunctionalInterface
  public interface ISetter&lt;T, R&gt; {
      void set(T object, R value);
  }
  </code></pre>
  
  <p>And this the method used to fetch the setter:</p>
  
  <pre><code>public ISetter getSetter(Class clazz, String fieldName, Class fieldType) throws Throwable {
  
      MethodHandles.Lookup caller = MethodHandles.lookup();
      MethodType setter = MethodType.methodType(Void.class, fieldType);
      MethodHandle target = caller.findVirtual(clazz, computeSetterName(fieldName), setter);
      MethodType func = target.type();
  
      CallSite site = LambdaMetafactory.metafactory(
              caller,
              "set",
              MethodType.methodType(ISetter.class),
              func.generic(),
              target,
              func
      );
  
      MethodHandle factory = site.getTarget();
      ISetter r = (ISetter) factory.invoke();
  
      return r;
  }
  </code></pre>
  
  <p>All setters are, by convention, named the same: "setField(...)".
  This is my test class:</p>
  
  <pre><code>public class TestEntity {
  
      private Long id;
  
  
      public TestEntity(Long id) {
          this.id = id;
      }
  
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  }
  </code></pre>
  
  <p>But when I execute this method for "id" and "Long.class" I get the follow exception:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoSuchMethodException: no such method: de.cyclonit.exercise.TestEntity.setId(Long)Void/invokeVirtual
      at java.lang.invoke.MemberName.makeAccessException(MemberName.java:871)
      at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1003)
      at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:1381)
      at java.lang.invoke.MethodHandles$Lookup.findVirtual(MethodHandles.java:859)
      at de.cyclonit.exercise.AccessorFactory.getSetter(AccessorFactory.java:41)
      at de.cyclonit.exercise.Main.main(Main.java:21)
  Caused by: java.lang.NoSuchFieldError: method resolution failed
      at java.lang.invoke.MethodHandleNatives.resolve(Native Method)
      at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:975)
      at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1000)
      ... 4 more
  </code></pre>
  
  <p>I don't understand where this error is coming from. The method "void setId(Long)" does exist.</p>
  
  <hr>
  
  <pre><code>public String computeSetterName(String fieldName) {
      return "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
  }
  </code></pre>
  
  <p>And the call:</p>
  
  <pre><code>ISetter setter = accessorFactory.getSetter(TestEntity.class, "id", Long.class);
  </code></pre>