Java 8: 'Effectively Final' Variables for Thread Safety

Java Insight: "Effectively final" variables Not every variable needs to final to be used in lamda. "Effectively final" - a concept introduced in java 8. A variable is effectively final if - - it is assigned only once - its value is never modified afterwards Example: int count = 5; list.forEach(item -> { System.out.println(count)}); Even though "count" is not declared as "final", Java treats it as final as its value is not changed. Advantage: - thread safety and predictable behaviour in lamda #Java #Java8 #JavaTips

To view or add a comment, sign in

Explore content categories