This is an automated email from the ASF dual-hosted git repository.
hepin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-pekko.git
The following commit(s) were added to refs/heads/main by this push:
new 6df4b88df4 chore: Move java 21 code to a dedicated folder and
including code sni… (#1023)
6df4b88df4 is described below
commit 6df4b88df457784e077f1fd77097dee9c23300f7
Author: He-Pin(kerr) <[email protected]>
AuthorDate: Tue Jan 23 14:37:32 2024 +0800
chore: Move java 21 code to a dedicated folder and including code sni…
(#1023)
* chore: Move java 21 code to a dedicated folder and including code snippe
with tab.
* chore: Update OptimizedActorWithJava21.java with new line.
---
.../actors/classical/OptimizedActorWithJava21.java | 33 ++++++++++++++++++
docs/src/main/paradox/actors.md | 40 ++++------------------
2 files changed, 39 insertions(+), 34 deletions(-)
diff --git
a/docs/src/main/java-jdk-21/docs/actors/classical/OptimizedActorWithJava21.java
b/docs/src/main/java-jdk-21/docs/actors/classical/OptimizedActorWithJava21.java
new file mode 100644
index 0000000000..ab43f2f35c
--- /dev/null
+++
b/docs/src/main/java-jdk-21/docs/actors/classical/OptimizedActorWithJava21.java
@@ -0,0 +1,33 @@
+
+// #pattern-matching
+
+static class OptimizedActorWithJava21 extends UntypedAbstractActor {
+ public static class Msg1 {}
+
+ public static class Msg2 {}
+
+ public static class Msg3 {}
+
+ @Override
+ public void onReceive(Object msg) throws Exception {
+ switch(msg) {
+ case Msg1 msg -> receiveMsg1((Msg1) msg);
+ case Msg2 msg -> receiveMsg2((Msg2) msg);
+ case Msg3 msg -> receiveMsg3((Msg3) msg);
+ default _ -> unhandled(msg);
+ }
+ }
+
+ private void receiveMsg1(Msg1 msg) {
+ // actual work
+ }
+
+ private void receiveMsg2(Msg2 msg) {
+ // actual work
+ }
+
+ private void receiveMsg3(Msg3 msg) {
+ // actual work
+ }
+}
+// #pattern-matching
diff --git a/docs/src/main/paradox/actors.md b/docs/src/main/paradox/actors.md
index 44e205bb8b..86fcccbd87 100644
--- a/docs/src/main/paradox/actors.md
+++ b/docs/src/main/paradox/actors.md
@@ -838,42 +838,14 @@ that the JVM can have problems optimizing and the
resulting code might not be as
untyped version. When extending `UntypedAbstractActor` each message is
received as an untyped
`Object` and you have to inspect and cast it to the actual message type in
other ways, like this:
-@@snip [ActorDocTest.java](/docs/src/test/java/jdocs/actor/ActorDocTest.java)
{ #optimized }
+In addition, Java 21 introduces [powerful pattern matching for
switch](https://openjdk.org/jeps/441) supporting any
+reference type. We can use `switch` instead of `if ... else ...` for
conditional branches:
-In addition, Java 21 introduces [powerful pattern matching for
switch](https://openjdk.org/jeps/441) supporting any reference type. We can use
`switch` instead of `if ... else ...` for conditional branches:
-
-```java
-static class PatternMatchedActor extends UntypedAbstractActor {
-
- public static class Msg1 {}
-
- public static class Msg2 {}
-
- public static class Msg3 {}
-
- @Override
- public void onReceive(Object msg) throws Exception {
- switch(msg) {
- case Msg1 msg -> receiveMsg1((Msg1) msg);
- case Msg2 msg -> receiveMsg2((Msg2) msg);
- case Msg3 msg -> receiveMsg3((Msg3) msg);
- default _ -> unhandled(msg);
- }
- }
-
- private void receiveMsg1(Msg1 msg) {
- // actual work
- }
-
- private void receiveMsg2(Msg2 msg) {
- // actual work
- }
+Java
+: @@snip
[ActorDocTest.java](/docs/src/test/java/jdocs/actor/ActorDocTest.java) {
#optimized }
- private void receiveMsg3(Msg3 msg) {
- // actual work
- }
- }
-```
+Java 21
+: @@snip
[OptimizedActorWithJava21.java](/docs/src/main/java-jdk-21/docs/actors/classical/OptimizedActorWithJava21.java)
{ #pattern-matching }
@@@
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]