This is an automated email from the ASF dual-hosted git repository.
He-Pin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git
The following commit(s) were added to refs/heads/main by this push:
new 51d64ff1dd refactor: use pattern matching instanceof (Java 16+) (#3192)
51d64ff1dd is described below
commit 51d64ff1ddf2ea5109cd5ba75d5160613171fef3
Author: He-Pin(kerr) <[email protected]>
AuthorDate: Fri Jun 26 16:23:19 2026 +0800
refactor: use pattern matching instanceof (Java 16+) (#3192)
Motivation:
Java 16 introduced pattern matching for instanceof, eliminating the need
for explicit casts after type checks.
Modification:
Replace old-style instanceof checks with explicit casts in
PingSerializerExampleTest and ActorDocTest. Most of the codebase
already uses pattern matching instanceof.
Result:
Cleaner code without redundant cast expressions.
---
.../org/apache/pekko/cluster/typed/PingSerializerExampleTest.java | 4 ++--
docs/src/test/java/jdocs/actor/ActorDocTest.java | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git
a/cluster-typed/src/test/java/jdocs/org/apache/pekko/cluster/typed/PingSerializerExampleTest.java
b/cluster-typed/src/test/java/jdocs/org/apache/pekko/cluster/typed/PingSerializerExampleTest.java
index 49c45871c0..473c9caeee 100644
---
a/cluster-typed/src/test/java/jdocs/org/apache/pekko/cluster/typed/PingSerializerExampleTest.java
+++
b/cluster-typed/src/test/java/jdocs/org/apache/pekko/cluster/typed/PingSerializerExampleTest.java
@@ -66,9 +66,9 @@ public class PingSerializerExampleTest {
@Override
public byte[] toBinary(Object obj) {
- if (obj instanceof Ping)
+ if (obj instanceof Ping ping)
return actorRefResolver
- .toSerializationFormat(((Ping) obj).replyTo)
+ .toSerializationFormat(ping.replyTo)
.getBytes(StandardCharsets.UTF_8);
else if (obj instanceof Pong) return new byte[0];
else
diff --git a/docs/src/test/java/jdocs/actor/ActorDocTest.java
b/docs/src/test/java/jdocs/actor/ActorDocTest.java
index d6f8e51ea4..e5e919947e 100644
--- a/docs/src/test/java/jdocs/actor/ActorDocTest.java
+++ b/docs/src/test/java/jdocs/actor/ActorDocTest.java
@@ -153,9 +153,9 @@ public class ActorDocTest extends AbstractJavaTest {
@Override
public void onReceive(Object msg) throws Exception {
- if (msg instanceof Msg1) receiveMsg1((Msg1) msg);
- else if (msg instanceof Msg2) receiveMsg2((Msg2) msg);
- else if (msg instanceof Msg3) receiveMsg3((Msg3) msg);
+ if (msg instanceof Msg1 msg1) receiveMsg1(msg1);
+ else if (msg instanceof Msg2 msg2) receiveMsg2(msg2);
+ else if (msg instanceof Msg3 msg3) receiveMsg3(msg3);
else unhandled(msg);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]