Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java out.println() how is this possible?

I've seen some code such as:

out.println("print something"); 

I tried import java.lang.System;

but it's not working. How do you use out.println() ?

like image 679
user69514 Avatar asked Mar 23 '10 22:03

user69514


2 Answers

static imports do the trick:

import static java.lang.System.out; 

or alternatively import every static method and field using

import static java.lang.System.*; 

Addendum by @Steve C: note that @sfussenegger said this in a comment on my Answer.

"Using such a static import of System.out isn't suited for more than simple run-once code."

So please don't imagine that he (or I) think that this solution is Good Practice.

like image 191
sfussenegger Avatar answered Oct 05 '22 09:10

sfussenegger


PrintStream out = System.out; out.println( "hello" ); 
like image 30
tangens Avatar answered Oct 05 '22 08:10

tangens