Why is Java's "out/in" PrintStream field designed to be referenced directly rather than using a getter

66 views Asked by At

This is something I've always been curious about since my first "Hello World"

Why is Java's out PrintStream a static field that is designed to be used rather than making something like a "getOut()" method that would return the PrintStream. Everything I've learned about good coding practices screams that this is the best way to do things. Why doesn't Java do it?

1

There are 1 answers

2
chrylis -cautiouslyoptimistic- On BEST ANSWER

The immediate reason is that the System streams predate the JavaBeans model with its get/set/is nomenclature, which was added in 1.1; the System streams go all the way back to 1.0, before even inner classes, so backwards compatibility demands continuity.

A related reason is that calls to getters can't be as efficiently inlined as direct field references, even if the methods are final, and since printing output is so common, it's likely that even today, those fields would be used directly.