title: Java 8 Consumer with additional parameters
body: <p>I want to write a generic DTO updater, which updates some of it's properties. My object looks like this:</p>
  <pre><code>class Person {
      String firsName;
      String lastName;
      Integer age;
      setter/getter
  }
  </code></pre>
  <p>I have an enum which defines which fields can be overridden:</p>
  <pre><code>enum OverriddenType {
      FIRST_NAME,
      LAST_NAME,
      AGE
  }
  </code></pre>
  <p>Instead of doing a &quot;hardcoded&quot; setter like this...</p>
  <pre><code>public void override(Person person, Map&lt;OverriddenType,Object&gt; newValuesForProperties) {
      newValuesForProperties.forEach((type,value)) -&gt; {
          if(type == OverriddenType.FIRST_NAME) {
              person.setFirstName((String)value);
          } else if(type == OverriddenType.LAST_NAME) {
              person.setLastName((String)value);
          } else if(type == OverriddenType.AGE) {
              person.setAge((Integer)value);
          }
      });
  }
  </code></pre>
  <p>... I would like to use some Java 8 Function/Consumer features to define the setters in each enum. I tried something like this:</p>
  <pre><code>enum OverriddenType {
      FIRST_NAME(p -&gt; p.setFirstName(???????)),  //don't know what to set here since the value is not here
      LAST_NAME(p -&gt; p.setLastName(???????)),
      AGE(p -&gt; p.setAge(???????));
      
      Consumer&lt;Person&gt; consumer;
      OverriddenType(Consumer&lt;Person&gt; consumer) {
          this.consumer = consumer;
      }
      public Consumer&lt;Person&gt; getConsumer();
  }
  </code></pre>
  <p>But as you can see I cannot pass the dynamic value here. Also don't know how the logic would look like, but I would imagine something like this:</p>
  <pre><code>public void override(Person person, Map&lt;OverriddenType,Object&gt; newValuesForProperties) {
      newValuesForProperties.forEach((type,value)) -&gt; 
          type.getConsumer().accept(person, value) // this doesn't exist, but I can imagine some additional parameter passing
      );
  }
  </code></pre>
  <p>Can you provide me a solution for this? Can it work? I am afraid that the incoming value is a dynamic therefore it won't work for enums..</p>