Search code examples
javaprintstream

On system.out, clarification needed


I was looking at someone's code and saw that he repeatedly declared

PrintStream out = System.out;

and later called

out.println("blah");

I actually thought this was kind of neat. Is this a common practice? Was he just being fancy?


Solution

  • This is a reasonable approach. He is basically creating an alias for System.out. There are a number of advantages:

    • Less typing.
    • Easier to later change the code to output to a different PrintStream.
    • Possibly a performance improvement, although it will be negligible.