• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why do this - PrintStream ps = System.out; ?

 
justin smythhe
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the purpose ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To assign System.out to ps.
 
justin smythhe
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:To assign System.out to ps.

Lol ! Agree ! But why not do System.out.print(); instead ?
 
Henry Wong
author
Marshal
Pie
Posts: 21437
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
justin smythhe wrote:
Bear Bibeault wrote:To assign System.out to ps.

Lol ! Agree ! But why not do System.out.print(); instead ?


One possibility -- a configuration option. The default option may be to print to standard out.... but the code wants the ability to route the output elsewhere, without routing the actual standard out. With a level of indirection, you can change where the standard output goes with a one line change of this config.

Henry
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably just being lazy. I do not approve.

Or what Henry suggested, which is better but ...
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
justin smythhe wrote:
Bear Bibeault wrote:To assign System.out to ps.

Lol ! Agree ! But why not do System.out.print(); instead ?


Because then you can just do ps.print(); instead. Less typing, right?

But really, System.out.println isn't a major feature of most real-life programs, so as Bear suggests, that's unnecessary laziness.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic