Java 8 - effectively final variables

Effectively final variable is a variable that has not been explicitly marked as final, but it doesn't change its value (basically, an implicit constant).

Effectively final variables can be referenced in lambdas, without the need to explicitly mark them as "final":

// s is effectively final (not changed anywhere)
String s = "foo";
 
// s can be referenced in the lambda
Callable<String> callable = () -> s;
 
callable.call(); // "foo"

Subscribe to Java 8 Resources

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe