println vs System.out.println in Scala

我怕爱的太早我们不能终老 提交于 2019-11-30 05:35:32

Predef.println is shortcut for Console.println and you can use Console.setOut or Console.withOut for redirecting.

Also, Console.setOut only affects the current thread while System.setOut affects the whole JVM. Additionally Scala 2.9 repl evaluates each line in its own thread, so Console.setOut is not usable there.

scala> val baos = new java.io.ByteArrayOutputStream
baos: java.io.ByteArrayOutputStream = 

scala> Console.withOut(baos)(print("hello"))

scala> println(baos)
hello
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!