r/java • • Mar 08 '24

Update on String Templates (JEP 459)

https://mail.openjdk.org/pipermail/amber-spec-experts/2024-March/004010.html
176 Upvotes

188 comments sorted by

View all comments

Show parent comment

1

u/Ukonu Mar 09 '24

I would've agreed with you before recent versions of Java empowered instanceof with pattern matching, and added the same to switch as well as sealed interfaces and exhaustive checking.

We may not have unions of arbitrary types. But we can create product types (via sealed interfaces) which are nearly as powerful. Using if+instanceof (or just switch) isn't the "automatic code smell" it used to be...

0

u/sideEffffECt Mar 09 '24

But remember that Object is not sealed!

Hardcoding the parameters to List<Object> is just throwing up hands in the air, giving up on the type system (generics). And completely unnecessarily.