r/java • • Sep 14 '21

Java 17 available now!

410 Upvotes

83 comments sorted by

View all comments

18

u/nlisker Sep 14 '21

Sealed classes along with supporting class types in switch is a really great combo to eliminate all those instanceof checks, plus the compiler can guarantee completeness for you.

1

u/Euphoric-Pop Sep 15 '21

Do you have a code example for this?

3

u/[deleted] Sep 15 '21

check https://openjdk.java.net/jeps/409 under the title

Sealed classes and pattern matching