Why is Collectors.collect not able to infer the types in this stream pipeline?
01:39 16 Aug 2026

The following code compiles and runs fine:

List letters = Arrays.asList("a", "b", "c", "d");
letters.stream().gather(
        Gatherer.ofSequential(
        (_,  t,  r)->r.push(t.toUpperCase()) ) )
        .forEach(System.out::println);

But the following does not compile.


String s = letters.stream().gather(
        Gatherer.ofSequential(
        (_,  t,  r)->r.push(t.toUpperCase()) ) ).collect(Collectors.joining());

Compilation error:

Exception in thread "main" java.lang.RuntimeException: Uncompilable code - no suitable method found for ofSequential((Void _, S[...]se()))
    method java.util.stream.Gatherer.ofSequential(java.util.stream.Gatherer.Integrator) is not applicable
      (cannot infer type-variable(s) T,R
        (argument mismatch; incompatible parameter types in lambda expression))
    method java.util.stream.Gatherer.ofSequential(java.util.stream.Gatherer.Integrator,java.util.function.BiConsumer>) is not applicable
      (cannot infer type-variable(s) T,R
        (actual and formal argument lists differ in length))
    method java.util.stream.Gatherer.ofSequential(java.util.function.Supplier,java.util.stream.Gatherer.Integrator) is not applicable
      (cannot infer type-variable(s) T,A,R
        (actual and formal argument lists differ in length))
    method java.util.stream.Gatherer.ofSequential(java.util.function.Supplier,java.util.stream.Gatherer.Integrator,java.util.function.BiConsumer>) is not applicable
      (cannot infer type-variable(s) T,A,R
        (actual and formal argument lists differ in length))

How can I fix it?

java java-stream