Rust v.s Java 17 Pattern Matching

preview_player
Показать описание
Rust Programming for Java Developers, Rust Pattern Matching v.s. Java 17 Pattern Matching deep dive.

- 00:00 - Intro
- 00:15 - Base Match v.s. Switch
- 01:22 - Rust Enum Data & Match
- 02:35 - Java Class Switch
- 03:50 - Java Sealed Class Switch
- 04:26 - Java Sealed Record Switch
- 05:14 - Rust enum ~ Sealed Record or Class?
- 05:11 - Rust match reference
- 06:46 - Rust Match Guards
- 07:35 - Java Switch Guards
- 08:23 - Destructuring in Java 18 / 19
- 08:57 - Rust nesting destructuring & matching
- 10:20 - Rust match tuple support
- 12:10 - Powder Day (i.e., no friend day)
- 13:07 - Conclusion

#RustLang #Java17 #Programming

Jeremy Chone:

=== Notes, Comments, and Credits:

Other popular Rust Programming videos:

Playlists:

Рекомендации по теме
Комментарии
Автор

8:25 the guard Syntax was experimental in java 17 like the output says and it actually was changed to use "when" instead of "&&" in the current experimental edition in java 19.

redcrafterlppa
Автор

Love your channel. Straight-to-the-point, clear, and concise explanations!
Looking forward to more Rust/Java videos.

Shankzzz
Автор

4:11 you can actually leave out the permits... when all subclasses are in the same java file (like in your example). You can also put the "case classes" inside the interface acting 99.9% like the rust version. You would even need to do the use... thing. In java it would be "import package.Main.Activity.*;"
Of course you would need to move the interface in the Main class instead of beneath it.

redcrafterlppa
Автор

Thanks a lot for these quick tutors, very high quality and useful for Java and not only devs.
btw, I like “public” pronunciation

also, one suggestion, keep the java and rust tabs on persistent sides, last two videos java has been on the left.

zzFluke
Автор

You are my second favorite French person :). Thanks for all the videos.

alpaslaneldemir
Автор

Excellent explanation of Rust destructuring and match

henrymaddocks
Автор

Great to find a fellow powder fan writing rust code!

LukeFrisken
Автор

11:40 is also possible with a record in java 19 using nested deconstruction. Records are just named tuples.
You would match on the in line named record and deconstruct with the record enclosing every case:
... main(...) {
record Pair(boolean weekend, Activity a) {}
var pair = new Pair(true, new Sleeping(8));
var msg = switch (pair) {
case Pair(boolean b, Sleeping(int i)) when b -> "...";
...
case Pair(boolean b, Coding c) -> "...";
} ;
...println(msg) ;
}

Trying this I discovered there is currently a bug (it's still in preview) the compiler doesn't recognize this pattern as complete and requests a default branch.

redcrafterlppa
Автор

10:27 nested deconstruction is planed to preview in java 20. It is planed to work like first level deconstruction you briefly showed earlier. It will aldo support "midway" deconstruction.
Sleeping(Option.Some(int i) o) s
As you can see we have access to Sleeping s, Option o and int i at the same time. Which is as far as I know not easily possible in rust match.

redcrafterlppa
Автор

Typo: in your video description table of contents, the 02.35 should be 02:35. That should fix the broken time code link.

rhymu
Автор

Me, stuck on JS and Java 8: my kingdom for ADT enums…

atalhlla