Skip to content

Java higher-order methods inconsistently require type annotations  #11558

Closed
scala/scala
#8129
@joshlemer

Description

@joshlemer

This works:

scala> import java.util.stream.Stream
import java.util.stream.Stream

scala> Stream.of(1,2,3).map(_ + 1)
res20: java.util.stream.Stream[?0] = java.util.stream.ReferencePipeline$3@27014faf

But then, you'd think that this should work:

scala> Stream.of(1,2,3).map(_.toString)
                              ^
       error: type mismatch;
        found   : Int => String
        required: java.util.function.Function[_ >: Int, _]

It can be made to work only by including the map type param:

scala> Stream.of(1,2,3).map[String](_.toString)
res22: java.util.stream.Stream[String] = java.util.stream.ReferencePipeline$3@7e7daeac

This would hopefully work because it does actually work in java:

Stream.of(1,2,3).map(i -> i.toString());

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions