Pattern Matching for switch

preview_player
Показать описание
Pattern matching has been added to switch! Let's take a look!

#Java21 #Java #openjdk #InsideJava
Рекомендации по теме
Комментарии
Автор

The omission of unnecessary default should have been thought of much earlier, tbh. I've had issues with it when I've tried to directly assign value through switch... I used to get around it by throwing exceptions knowing that it's really just an unreachable statement. Good to see it's being implemented now.

sen
Автор

Interesting behavior. I would have filed this video under "new behavior of the switch expression" instead of "pattern matching" While I see the intent of the guarded case expressions, I see that quickly degenerating into what many newbies incorrectly think is great: unmanageable long winded in-place expressions.

sidneymonteiro
Автор

Question. In most cases is use of the newest Java version a matter of preference or "only if you want to SAVE YOUR SANITY DUHH"?

Was thinking on it, and concluded that most ppl would be inclined to answer the latter. Thoughts?

gerdsfargen
Автор

It seems the sealed interface misses the permit Circle, Square for this to work as intended :)

DennisGyldendahlJensen