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

后端 未结 7 1215
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 09:30

It seems strange that I can\'t import static java.lang.System.out.println, when I can import static java.lang.Math.abs. Is there some reason behind this or am I doing somet

7条回答
  •  隐瞒了意图╮
    2020-12-05 10:16

    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
    

提交回复
热议问题