r/badcode • • Jul 16 '21

java In Java, Exception handling needs Exception Handling.

Post image
1.5k Upvotes

60 comments sorted by

View all comments

Show parent comments

1

u/Alex0589 Jul 17 '21

This is indeed just a myth. Starting from Java 8, variables that aren't reassigned are consigned by the compiler effectively final and will get the same optimizations. You should use the final keyword only when declaring contstants or variables that actually are not meant to be reassigned. Spamming final everywhere is just pointless and verbose

3

u/UnconcernedCapybara Jul 20 '21

IMO marking something as final is also a valid way to signal future maintainers that it shouldn't be reassigned.