The Javadoc for PrintStream.println(String) says "Prints a String and then terminate the line. This method behaves as though it invokes print(String) and then println()."
(Side note: there's a typo; "terminate" should be plural)
But that's now how it actually behaves. Instead, it behaves as if it invokes print(String) and then INVOKESPECIAL PrintStream.println().
Test case:
import java.io.*;
public class CrNlTest {
public static void main(String[] args) throws Exception {
try (PrintStream out = new PrintStream(System.out, true) {
@Override
public void println() {
this.print("***");
super.println();
}
}) {
// Scenario 1
out.println("test"); // outputs 74 65 73 74 0a
// Scenario 2
out.print("test"); // outputs 74 65 73 74 2a 2a 2a 0a
out.println();
}
}
}
Expected output:
test***
test***
Actual output:
test
test***
(Side note: there's a typo; "terminate" should be plural)
But that's now how it actually behaves. Instead, it behaves as if it invokes print(String) and then INVOKESPECIAL PrintStream.println().
Test case:
import java.io.*;
public class CrNlTest {
public static void main(String[] args) throws Exception {
try (PrintStream out = new PrintStream(System.out, true) {
@Override
public void println() {
this.print("***");
super.println();
}
}) {
// Scenario 1
out.println("test"); // outputs 74 65 73 74 0a
// Scenario 2
out.print("test"); // outputs 74 65 73 74 2a 2a 2a 0a
out.println();
}
}
}
Expected output:
test***
test***
Actual output:
test
test***
- links to