For simple laziness reasons, I get annoyed having to type the full System.out.println("...");
in Java code. Why would it be bad programming practice (if at all) to do something like this?
import java.io.PrintWriter;
public class RenameSystemOut{
public static void main(String[] args){
PrintWriter w = new PrintWriter(System.out);
w.println("Hello, world");
w.close();
}
}
My guess is that it risks the programmer forgetting to close()
the resource. But I imagine that in a long program with many print statements, you could save yourself a lot of trouble.
new PrintWriter(System.out, true)
to wrap, which enables auto-flush; otherwise you'll have to explicitly callflush()
every so often to get the printed text actually show up on stdout.