8000 The documentation for Akka/Java could be upgraded to use Java 16 records? · Issue #32522 · akka/akka · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

The documentation for Akka/Java could be upgraded to use Java 16 records? #32522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dtonhofer opened this issue Sep 25, 2024 · 1 comment
Open
Labels
1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted t:docs t:java Related to the Java APIs

Comments

@dtonhofer
Copy link

An example from https://doc.akka.io/docs/akka/current/typed/interaction-patterns.html

public class Printer {
    public static class PrintMe {
        public final String message;

        public PrintMe(String message) {
            this.message = message;
        }
    }

    public static Behavior<PrintMe> create() {
        return Behaviors.setup(
                context ->
                        Behaviors.receive(PrintMe.class)
                                .onMessage(
                                        PrintMe.class,
                                        printMe -> {
                                            context.getLog().info(printMe.message);
                                            return Behaviors.same();
                                        })
                                .build());
    }
}

Since Java 16 ( March 2021), the immutable message classes can be written as records, significantly reducing visual clutter:

public class Printer {

    public record PrintMe(String message) {}

    public static Behavior<PrintMe> create() {
        return Behaviors.setup(
                context ->
                        Behaviors.receive(PrintMe.class)
                                .onMessage(
                                        PrintMe.class,
                                        printMe -> {
                                            context.getLog().info(printMe.message);
                                            return Behaviors.same();
                                        })
                                .build());
    }
}

Maybe something to do progressively.

@johanandren
Copy link
Contributor

I agree, Java 16+ yields much more pleasant code both to read and to write.

The main reason we have not migrated all samples in docs yet is that then those samples will no longer compile on JDK 11, which we still support. Some sample code is in the doc module so could be fine but some are mixed with module tests which we would have to investigate time to separate.

For the record we also have a few newer APIs specifically catered to newer JDK features, in the docs:

@johanandren johanandren added 1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted t:docs t:java Related to the Java APIs labels Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted t:docs t:java Related to the Java APIs
Projects
None yet
Development

No branches or pull requests

2 participants
0