There are plenty of articles on calling Java varargs from Scala code, but the only thing I could find the opposite way round was this question: Using scala vararg methods in java, which doesn't have any concrete examples.
I'm trying to use scala.Console
from some Java code, for the reason that java.io.Console
doesn't work in Eclipse, whereas the Scala one does. But I cannot get the method
def readLine (text: String, args: Any*): String
to work because it seems to be expecting a scala.collection.Seq[Any]
for the second argument, and I don't see how to create a Seq
in Java. How can I work around this?
Things I've tried:
1) Using null
// Java
String s = scala.Console.readLine("Enter text: ", null);
- get rewarded with a NullPointerException
.
2) Replacing the null
with scala.collection.Seq.empty()
, but javac reports all sorts of errors such as Seq
not having an empty
method.
3) Using the Nil
object in the scala.collection.immutable
package object, but the syntax suggested here, which would be scala.collection.immutable.package$Nil$.MODULE$
, but that can't be resolved.
Of course I could just use the readLine()
method that doesn't take varargs, but that would be too easy.