How to disambiguate call to Stream.of?


results in

ambiguous reference to overloaded definition,
both method of in object Stream of type [T](x$1: T*)[T]
and  method of in object Stream of type [T](x$1: T)[T]

The Scala compiler (version 2.11.12) doesn’t seem to know to use the 2nd method when there’s only one argument. I can disambiguate to use the varargs version with

Stream.of(Seq(statement): _*)

but really I want the other method. I randomly found that


also compiles. I decompiled the class and found that it uses the singleton method rather than varargs. Why? Is there a better way to force it to use the one I want?

Seems like this got fixed in 2.13. But I guess you’re not using 2.11 because you enjoy the pain.

I’m glad it’s fixed in newer versions. But yes we’re stuck with 2.11 just due to the effort of upgrading. Even if we did, we can’t go beyond 2.12 due to Spark support.

You could use the scala-java8-compat module which provides a few extras for better Scala / Java interop, also for Stream.

But I think for you problem at hand you already got a solution that is not too cumbersome.

Of course, you could write a Java Wrapper which always just calls the one argument method.

1 Like