On Sat, 5 Apr 2025 02:31:21 GMT, Chen Liang <li...@openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/IO.java line 122: >> >>> 120: public static void print(Object obj) { >>> 121: System.out.print(obj); >>> 122: System.out.flush(); >> >> Is it worth using a local variable to avoid calling `print` and `flush` on >> different streams in case `System.out` is reassigned in between? >> >> >> var out = System.out; >> out.print(obj); >> out.flush(); > > This code is not that perf sensitive, guess it is fine as-is I think there's a correctness angle. If you print something to a stream you want to flush the same stream. If System.out is changed in between (unlikely, but possible) then output destined for the old stream could be stranded in its buffer. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/24438#discussion_r2031674696