Which line separator in println?

The documentation for Predef.println (or Console.println) states:

Prints out an object to the default output, followed by a newline character.

But it looks like the default output is java.lang.System.out and that Predef.println uses out.println, which states:

The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n').

So, which is it?

1 Like

system property line.separator, and is not necessarily a single newline character ('\n').

This is the important part - on normal systems that’s \n by default, but on Windows that’s \r\n digraph.

Since both Console.withOut and System.setOut allow to set a custom PrintStream the final result depends on the implementation of non-final PrintStream instance, since PrintStream.println is not a final method.

1 Like

I understand that, but isn’t the documentation on the Scala side a bit misleading? Maybe it should say: “followed by a line separator”?

1 Like

FWIW, I dug up this very old slide (apologies for the gratuitous, cringeworthy mugshot)

Fixing this in Doc: clarify behavior of line-related functions by SolalPirelli · Pull Request #27047 · scala/scala3 · GitHub