Skip to content

Replace System.out.print(ln) with IO.print(ln) #846

@tfeuerba

Description

@tfeuerba

What problem are you trying to solve?

JEP 512, JDK-8305457 added a new IO class to JDK 25 that is automatically imported (as it is part of java.lang). It offers convenient methods to read and write from standard input and output. While aimed at beginners, it is a concise way to print to the console, and will feel natural to anyone who started their Java journey at version 25.

What precondition(s) should be checked before applying this recipe?

JDK version >= 25

Describe the situation before applying the recipe

class A {
    static void main() {
        System.out.print("Please enter your name: ");
        String name = IO.readln();
        System.out.println("Hello " + name);
    }
}

Describe the situation after applying the recipe

class A {
    static void main() {
        IO.print("Please enter your name: ");
        String name = IO.readln();
        IO.println("Hello " + name);
    }
}

Any additional context

Note that IO does not offer a way to print formatted strings, so System.out.printf will remain unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions