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?
The immediate reason is that the
System
streams predate the JavaBeans model with itsget/set/is
nomenclature, which was added in 1.1; theSystem
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.