Java8 Lambda Capturing Static Variable
Before Java 8, when we needed to use a local variable inside inner class, the local variable had to be declared final.
However in Java 8 you don’t have this restriction anymore. It is now possible to refer to the variables that are NOT final but they still need to be effectively final. And this applies to both anonymous inner classes and lambdas expressions
Creating Program in Java8(Lambda) for Capturing Static Variable
Follow the below steps to write program with java8(Lambda).
Step-1 Create a package java8lambdabasics under sources package. Then create the Java class CaptureStaticVariable.java. Once you are ready then write the code as shown below.
Output CaptureStaticVariable.java
Download example and run it on Netbeans IDE