refactor: modernize Java example code with Java 17 features#171
Closed
He-Pin wants to merge 1 commit into
Closed
Conversation
Motivation: Java 17 introduced records, pattern matching for instanceof, and other features that make Java code more concise and readable. The example code contained many verbose data carrier classes and instanceof patterns that can be significantly simplified. Modification: - Convert data carrier classes (commands, events, messages) to Java records in sample applications: ShoppingCart, ClusterClient, ReplicatedCache, VotingService, ThumbsUpCounter - Use pattern matching for instanceof to eliminate explicit casts - Update all field accesses from direct field access to record accessor methods - Remove redundant equals/hashCode/constructor boilerplate Result: Example Java code is more concise and idiomatic for Java 17+, reducing boilerplate while maintaining the same behavior. Net reduction of ~350 lines of code across 6 files. Tests: Not run - sample applications without automated test suite References: None - code modernization
pjfanning
reviewed
Jun 18, 2026
pjfanning
left a comment
Member
There was a problem hiding this comment.
our samples are still pekko 1 based and that probably means also supporting java 8
Member
Author
|
Closing this PR as pekko-samples still needs to support Java 8 (pekko 1.x based), which means Java 17 records cannot be used. Thanks @pjfanning for the review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Java 17 introduced records, pattern matching for instanceof, and other features that make Java code more concise and readable. The example code contained many verbose data carrier classes and instanceof + explicit cast patterns that can be significantly simplified.
Modification
Files changed:
pekko-sample-persistence-java/: ShoppingCartpekko-sample-distributed-data-java/: ShoppingCart, VotingService, ReplicatedCachepekko-sample-cluster-client-grpc-java/: ClusterClientpekko-sample-persistence-dc-java/: ThumbsUpCounterResult
Example Java code is more concise and idiomatic for Java 17+, reducing boilerplate while maintaining the same behavior. Net reduction of ~350 lines of code across 6 files.
Tests
Not run - sample applications without automated test suite
References
None - code modernization