Java 8 Stream API Collector - addAll not applicable for argument Object, addAll is undefined for type Object
<p>My code is not compiling and I'm not quite sure why. Here is the code:</p>

<pre><code>ArrayList&lt;ClassificationData&gt; classifications = productData
                .stream()
                .filter(p -&gt; CollectionUtils.isNotEmpty(p.getClassifications()))
                .flatMap(p -&gt; p.getClassifications().stream())
                .collect(groupingBy(ClassificationData::getName,
                        mapping(ClassificationData::getFeatures,
                                Collector.of(LinkedHashSet&lt;FeatureData&gt;::new,
                                        (a,b) -&gt; b.addAll(a),
                                        (a,b) -&gt; {
                                            b.addAll(a);
                                            return b;
                                        })
                        )))
                .entrySet()
                .stream()
                .map(e -&gt; {
                    ClassificationData c = new ClassificationData();
                    c.setName(e.getKey());
                    c.setFeatures(e.getValue());
                    return c;
                })
                .collect(Collectors.toCollection(ArrayList::new));
</code></pre>

<p>And the errors:</p>

<pre><code>    (a,b) -&gt; b.addAll(a),
The method addAll(Collection&lt;? extends FeatureData&gt;) in the type Collection&lt;FeatureData&gt; is not applicable for the arguments (Object)

     b.addAll(a);
The method addAll(Object) is undefined for the type Object

     c.setFeatures(e.getValue());
The method setFeatures(Collection&lt;FeatureData&gt;) in the type ClassificationData is not applicable for the arguments (Object)
</code></pre>

<p>I've also tried Set::add and Set::addAll with pretty much the same result.</p>

<p>EDIT:</p>

<p>I've ended up with this code. Please tell me if there is a cleaner way to do this, or is it ok?</p>

<pre><code>ArrayList&lt;ClassificationData&gt; classifications = productData
                .stream()
                .filter(p -&gt; CollectionUtils.isNotEmpty(p.getClassifications()))
                .flatMap(p -&gt; p.getClassifications().stream())
                .collect(groupingBy(ClassificationData::getName,
                        mapping(ClassificationData::getFeatures,
                                toCollection(LinkedHashSet::new)
                        )))
                .entrySet()
                .stream()
                .map(e -&gt; {
                    ClassificationData c = new ClassificationData();
                    c.setCode(e.getKey());
                    c.setName(e.getKey());
                    c.setFeatures(e.getValue()
                            .stream()
                            .filter(CollectionUtils::isNotEmpty)
                            .flatMap(p -&gt; p.stream())
                            .filter(distinctByKey(FeatureData::getName))
                            .collect(toCollection(ArrayList::new)));
                    return c;
                })
                .collect(toCollection(ArrayList::new));
</code></pre>