|
Oktatás * Programozás 2 * Szkriptnyelvek * Adator. prog. Teaching * Prog. for Data Sci. Félévek Linkek * kalendárium |
Scala /
Java → Scala / Scala → Java
Say you want to use the
ProcessBuilder(List<String> command)
This constructs a process builder with the specified operating system program and arguments.
List<String> command()
This method returns this process builder's operating system program and arguments.
As can be seen, the constructor needs a
import scala.collection.JavaConversions.bufferAsJavaList // buffer TO Java List
import scala.collection.mutable.ArrayBuffer
val cmd = ArrayBuffer("ls", "-al", "/tmp") // create your buffer
val pb = new ProcessBuilder(cmd) // automatically converted to Java List
Let's see the other direction, i.e. converting a Java
import scala.collection.JavaConversions.asScalaBuffer // (Java List) TO Scala Buffer
import scala.collection.mutable.Buffer
val b: Buffer[String] = pb.command() // Can't use ArrayBuffer!
// the wrapped object is only guaranteed to be a Buffer
// b: scala.collection.mutable.Buffer[String] = ArrayBuffer(ls, -al, /tmp)
|
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |