title: Type mismatch when processing a stream with maxBy()
body: <p>I'm writing a code to handle Mountain Huts in different municipalities in different provinces. I'm trying to compute the maximum number of beds available in a single mountain hut per altitude range. If the altitude of the mountain hut is not available, i'll use the
  altitude of its municipality.
  I would like my method to return a <code>Map&lt;String, Optional&lt;Integer&gt;&gt;</code> but i'm getting a <code>Map &lt;String , Optional&lt;MountainHut&gt;&gt;</code> . Now i am aware of the fact that the Optional i am getting is actually the one who has the maximum bed number but i am struggling to get the right data type.</p>
  
  <pre><code>public Map&lt;String, Optional&lt;Integer&gt;&gt; maximumBedsNumberPerAltitudeRange()
  {
      return this.getMountainHuts().stream()
          .collect(
              Collectors.groupingBy((MountainHut mountainHut) -&gt;
                  this.getAltitudeRange(
                      mountainHut.getAltitude().orElse(mountainHut.getMunicipality().getAltitude())
                  ),
                  Collectors.maxBy(Comparator.comparing(MountainHut::getBedsNumber))
              )
          );
  }
  </code></pre>
  
  <p>For completeness i'll post also the getAltitudeRange method, the other 
  methods are just getters. </p>
  
  <pre><code>public String getAltitudeRange(Integer altitude) {
      Range r = ranges.stream()
          .filter((x) -&gt; altitude&gt;= x.getMin() || altitude &lt;= x.getMax())
          .findFirst()
          .orElse(new Range(0,Integer.MAX_VALUE));
      ranges.stream().close();
      if(r.getMax() == Integer.MAX_VALUE)
      {
          return (0 +" - "+ "INF");
      }
      return (r.getMin() + " - " + r.getMax());
  }
  </code></pre>
  
  <p>Altitude is an Optional attribute of the class MountainHut</p>
  
  <p>As expected the error message is the following:
  Type mismatch: cannot convert from Map> to 
   Map></p>