Q:

Why does one version of this Java stream work on a Static Map while the other fails?

I've got a static map:
private static final Map<SomeObject, AnotherObject> SOME_MAP = ...build map here...

I'm trying to generate a single list of type List<AnotherObject>
This works as expected:
List<AnotherObject> list = Stream.of(SOME_MAP.values())
  .flatMap(Collection::stream)
  .collect(Collectors.toList());

The following fails due to non-static method cannot be referenced in static context
List<AnotherObject> list = SOME_MAP.values().stream()
  .flatMap(Collection::stream)
  .collect(Collectors.toList());

Can anyone explain exactly how the second version is encounting a non-static method error while the first version does not?
Here's a concrete example:
private static final Map<Integer, Integer> SOME_MAP = ImmutableMap.of(1, 2, 3, 4, 5, 6);

@Test
public void workingTest() {
 List<Integer> list = Stream.of(SOME_MAP.values())
    .flatMap(Collection::stream)
    .collect(Collectors.toList());

   System.out.println(list); // prints out [2, 4, 6]
}

@Test
public void nonWorkingTest() {
 List<Integer> list = SOME_MAP.values().stream()
    .flatMap(Collection::stream)
    .collect(Collectors.toList());

   System.out.println(list); // Fails before this.
}

With the failing test I get the following error:
Error:(79, 17) java: incompatible types: cannot infer type-variable(s) R
(argument mismatch; invalid method reference
  method stream in interface java.util.Collection<E> cannot be applied to given types
    required: no arguments
    found: java.lang.Integer
    reason: actual and formal argument lists differ in length)

 Error:(79, 18) java: invalid method reference
    non-static method stream() cannot be referenced from a static context

A:

The answer is simple. Both variants are giving back different Streams.
Stream.of(SOME_MAP.values()) results in a Stream<Collection<AnotherObject>>.
On the other hand SOME_MAP.values().stream() results in a Stream<AnotherObject>. You don't need to call Stream::flatMap on it.

