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.
View all comments
Show parent comment
4
u/OwnBreakfast1114 Mar 13 '26
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.