Here is a workable example of the answers on this page, as well as a related question . I'm not sure if any of these shortcuts are recommended for readable, reusable code.
import static java.lang.System.out; // only for method of minichate&Tim Cooper import java.io.PrintWriter;// only for method of Stephan Paul public class PrintExample{ public static void main(String[] args){ out.println("Typing of 7 characters saved!"); p.pl("shortened System.out.println, 14 characters saved."); p.pl(77); // takes non-strings p.out(88); // also takes non-strings p.print("sorry, I only take strings!"); //p.print(99); compilation error, int cannot be converted to String PrintWriter pr = new PrintWriter(System.out, true); pr.println(33); // method of Stephan Paul } } class p{ // using generics (Java 5.0 onwards), by carlos_lm public static <T> void pl (T obj){ System.out.println(obj); } // method by Neji3971 & bakkal, seems to work for all objects public static void out(Object o){ System.out.println(o.toString()); } // method by Jesus Ramos & rup. Only accepts strings!! public static void print(String s) { System.out.println(s); } }
Mark teese
source share