Roiocam commented on code in PR #1023:
URL: https://github.com/apache/incubator-pekko/pull/1023#discussion_r1464404398
##########
docs/src/main/java-jdk-21/docs/actors/classical/OptimizedActorWithJava21.java:
##########
@@ -0,0 +1,33 @@
+
+// #pattern-matching
+
+static class OptimizedActorWithJava21 extends UntypedAbstractActor {
Review Comment:
should also add there source directory on the build script, as JDK9.scala
does.
##########
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
Review Comment:
Looks great, this is kind of like
[Tabs](https://docusaurus.io/docs/markdown-features/tabs) feature in docusaurus.
I often use Tabs when writing release notes at work.
I think this is a good example when we add the newest JDk-related features
in the future.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]