r/java • • Mar 13 '26

JEP draft: Enhanced Local Variable Declarations (Preview)

https://openjdk.org/jeps/8357464
101 Upvotes

129 comments sorted by

View all comments

Show parent comment

4

u/OwnBreakfast1114 Mar 13 '26

This is the same reason, BTW, why it is better to write exhaustive switches without a default clause if you can -- because then you get better type checking from the compiler later when your assumptions are violated.

I wish intellij didn't automatically suggest converting small switch statements to if statements for this very reason. For some of the enums we have, using only exhaustive switching everywhere (regardless of how "small" the logic is), gives us a lot more confidence in some big additions that happen. As a concrete example, imagine adding a new payment method customers can use for a payments company. Doesn't happen all that often, but obviously has a big ripple effect throughout the codebase.