Is there a way to add a method to System.out called printlnx that would prefix output with a string?
So, if I called :
System.out.printlnx("This is a test");
That it would print that with a prefix (specified by me) :
-prefix-->This is a test
NOTE: My intention is to mark all output from a console program so that its output appears distinct from a secondary console program that I run afterwards.
No.
System.outis actually an object of typePrintStream. You can’t retrospectively add arbitrary methods to a particular object.But you can very easily write one that lives in your own namespace:
Then elsewhere: