On Sat, 5 Apr 2025 00:55:55 GMT, Luca Kellermann <d...@openjdk.org> wrote:
>> This is a PR that implements JEP: Compact Source Files and Instance Main >> Methods. Changes include: >> - `java.io.IO` moved to `java.lang.IO`, and no longer uses >> `System.console()` to implement the methods (thanks to @stuart-marks) >> - `java. ... .IO` is no longer automatically imported in any compilation unit >> - the feature is finalized (i.e. no longer requires `--enable-preview`) > > 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 > src/java.base/share/classes/java/lang/IO.java line 147: > >> 145: } catch (IOException ioe) { >> 146: throw new IOError(ioe); >> 147: } > > Was `UncheckedIOException` considered? It might be better for beginners to > learn throwing exceptions instead of errors. This implementation is not to be emulated by beginners. If an Exception.is thrown here, a user might be tempted to add handlers in their code, while this is an issue with the setup. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/24438#discussion_r2029660072 PR Review Comment: https://git.openjdk.org/jdk/pull/24438#discussion_r2029659899