I\'m playing with lambdas in Java 8 and I came across warning local variables referenced from a lambda expression must be final or effectively final
. I know tha
If you could add the
final
modifier to a local variable, it was effectively final.
Lambda expressions can access
static variables,
instance variables,
effectively final method parameters, and
effectively final local variables.
Source: OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide, Jeanne Boyarsky, Scott Selikoff
Additionally,
An
effectively final
variable is a variable whose value is never changed, but it isn’t declared with thefinal
keyword.
Source: Starting Out with Java: From Control Structures through Objects (6th Edition), Tony Gaddis
Furthermore, don't forget the meaning of final
that it is initialized exactly once before it is used for the first time.