Why can't I import static java.lang.System.out.println?

Math is a class, on which abs is a static method. System.out is a static field rather than a class. So its println method isn't actually a static method, but an instance method on a static field.


Because java.lang.System.out is a static object (a PrintStream) on which you call println.

Though in eclipse you can type sysout and then press ctrl-space to have it expanded to System.out.println();


Non-static methods cannot be imported that way.

However, you can do this:

public static void println() {
    System.out.println();
}

// elsewhere
println();     // can be inlined

Tags:

Java