Scala implicit conversion to a Java array not working -


i'm pretty new scala , i've hit first hurdle ...

java.nio.file.paths has method:

public static path get(string first, string ... more) 

this java code compiles (and runs):

string[] tokens = new string[] { "/home", "toby", "mydir" }; path path = paths.get(tokens[0], arrays.copyofrange(tokens, 1, tokens.length -1)); 

however scala code not compile:

import collection.javaconversions._ ... val tokens = array("/home", "toby", "mydir") val path = paths.get(tokens(0), tokens.tail) 

the error "type mismatch; found : array[string] required: string"

what missing? thanks

paths.get not want array second parameter, string... more varargs notation.

try:

val path = paths.get(tokens.head, tokens.tail: _*) // path: java.nio.file.path = /home/toby/mydir 

look @ this question more explanation on _*.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -