Question: I am trying to put all the values treeset elements of a list with treesets into a `linkedHashSet`. This list of treesets is returned by the `values()` method of a `TreeMap<String, TreeSet>`. The code looks like this:

```
Map<String, TreeSet> sortedByMonthAndVarietyNameMap = new HashMap<>();
    sortedByMonthAndVarietyNameMap.values().stream().flatMap(monthList -> monthList.stream()).collect(Collectors.toCollection(LinkedHashSet::new));

```

This should be returning a `LinkedHashSet` with all the elements of the flatmapped treesets. But in reality it returns an object of type `Object`.

Why is this happening? Can someone explain what i'm doing wrong?

Answer: 
The TreeSet is not fully typed:

```
Map<String, TreeSet<Integer>> sortedByMonthAndVarietyNameMap = new HashMap<>();
LinkedHashSet<Integer> result = sortedByMonthAndVarietyNameMap.values().stream()
        .flatMap(monthList -> monthList.stream())
        .collect(Collectors.toCollection(LinkedHashSet::new));

```
As you have provided the constructor reference of LinkedHashSet without specifying the type.

<https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.13>