Commits

Tim Vernum committed e3c72ad

Add effectively final variable

  • Participants
  • Parent commits fa8c2e3

Comments (0)

Files changed (1)

File ConvertingJava8To7.md

 
     Runnable runnable = () -> { System.out.println("Running!"); } ;
 
-    Callable<String> callable = () -> "abc" ;
+    String str = "abc";
+    Callable<String> callable = () -> str ;
 
     FileFilter filter = (file) -> file.getName().endsWith(".xml") ;
 
 * Implied argument types _(`filter`, `listener`)_
 * Generics _(`callable` and `cmp`)_
 * Generics with wildcards _(`cmp`)_
+* Effectively final variables _(`str` in `callable`)_
 
 The resulting Java 7 code for these statements is:
 
         public void run() { System.out.println("Running!"); }
     };
 
+    final String str = "abc";
     Callable<String> callable = new Callable<String>() {
-        public String call() throws java.lang.Exception { return "abc"; }
+        public String call() throws java.lang.Exception { return str; }
     };
 
     FileFilter filter = new FileFilter() {