In Java 8, Java designers have come up with the notion of an effectively final variable, that is a variable which would not give compiler error if it were to be appended by 'final'. My question is what does this newly made concept of 'effectively final' offer over the classical 'final'? As a Java developer what benefits do I actually get?
Asked
Active
Viewed 507 times
-1
-
It's just a convenience. – shmosel Apr 05 '18 at 23:42
-
You get the benefit of not having to type `final`. – 4castle Apr 05 '18 at 23:45
-
@4castle : so technically speaking, it is just less 'boilerplate' code. right? – ecdhe Apr 05 '18 at 23:46
-
1That is correct – 4castle Apr 05 '18 at 23:47
1 Answers
0
The effectively final variables can be used in a lambda expression. Think about it this way. Here is a case - a variable had to be explicitly declared final if you wanted to use it in an inlined /anonymous class (think Swing listeners). Now you can also use effectively final variables, since lambda expressions are in effect anonymous inner classes.

Prashant
- 1,002
- 13
- 29