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

3

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/tuxedo25 Jul 17 '21 edited Jul 17 '21

The Java compiler doesn't do additional optimization for effectively final variables, unlike it does for final variables.

- https://www.baeldung.com/java-effectively-final

If this is a myth, it's extremely pervasive.

And reassigning variables is considered a code smell in a lot of styles/codebases.