[ACCEPTED]-Convert java.lang.String to Scala string-scala-java-interop

Accepted answer
Score: 11

It's not a wrapper, but actually java.lang.String. No 1 need in additional hassle:

» touch 123
» scala
...

val foo = new java.io.File("123")
// java.io.File = 123

// Get name is a java api, which returns Java string

foo.getName.toInt
// res2: Int = 123
Score: 4

java.lang.String is implicitly amended with Scala specific 2 string methods so no manual conversion should 1 be necessary.

Score: 0

Use asInstanceOf[String] to syntactically 1 convert Java string to Scala string.

val str: String = "java_string".asInstanceOf[String]

More Related questions