Java out.println() how is this possible?

前端 未结 9 1426
难免孤独
难免孤独 2020-12-08 13:42

I\'ve seen some code such as:

out.println(\"print something\");

I tried import java.lang.System;

but it\'s not working

9条回答
  •  粉色の甜心
    2020-12-08 14:11

    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.

提交回复
热议问题