How to make System.out.println() shorter

后端 未结 12 998
伪装坚强ぢ
伪装坚强ぢ 2020-12-04 07:10

Please advice on where can I find the lib in order to use the shorter expression of System.out.println() and where should I place that lib.

12条回答
  •  死守一世寂寞
    2020-12-04 07:39

    Logging libraries

    You could use logging libraries instead of re-inventing the wheel. Log4j for instance will provide methods for different messages like info(), warn() and error().

    Homemade methods

    or simply make a println method of your own and call it:

    void println(Object line) {
        System.out.println(line);
    }
    
    println("Hello World");
    

    IDE keyboard shortcuts

    IntelliJ IDEA and NetBeans:

    you type sout then press TAB, and it types System.out.println() for you, with the cursor in the right place.

    Eclipse:

    Type syso then press CTRL + SPACE.

    Other

    Find a "snippets" plugin for your favorite text editor/IDE

    Static Import

    import static java.lang.System.out;
    
    out.println("Hello World");
    

    Explore JVM languages

    Scala

    println("Hello, World!")
    

    Groovy

    println "Hello, World!" 
    

    Jython

    print "Hello, World!" 
    

    JRuby

    puts "Hello, World!" 
    

    Clojure

    (println "Hello, World!")
    

    Rhino

    print('Hello, World!'); 
    

提交回复
热议问题