title: Java 8 stream: collecting a map to a map and constructors
body: <p>I understand how you can process the entries of a map and collect the resulting stream into a different map. But I need to put the value using a constructor to which the previous map's key is passed and I can't figure out how to do it.</p>
  
  <p>The scenario is the following:</p>
  
  <p>I have a <code>Map&lt;Event, EventSchedule&gt; schedules</code>, and I want to get a <code>Map&lt;Event, InverseSchedule&gt;</code> from it. An <code>InverseSchedule</code> is constructed with an <code>Event</code>, precisely each key in <code>schedules</code>.</p>
  
  <p>This is what I tried so far, and I am just one piece away from finally achieving what I'm after:</p>
  
  <pre><code>Map&lt;Event, InverseSchedule&gt; inverseSchedules = schedules.get()
          .keySet()
          .stream()
          .collect(Collectors.toMap(Function.identity(), ???));
  </code></pre>
  
  <p>I have tried <code>InverseSchedule::new</code> but of course that doesn't work because I am passing no arguments, and I couldn't do it using a lambda either.</p>
  
  <p>I am still struggling to understand these new Java 8 features. I would really appreciate if the answer included the explanation of <em>why it works</em> rather than just providing the missing piece.</p>