Commits

Tim Vernum committed c3b52b1

Add documentation for member references

Comments (0)

Files changed (1)

ConvertingJava8To7.md

     };
 
 
+### Method and Constructor references
+_Method references_ and _constructor references  are supported in a variable declaration.
 
-Not Yet Supported Features
+e.g.
+    Callable<String> c = this::toString;
+    ChangeListener listener = ChangeEvent::toString;
+    Runnable runnable = MyClass::execute;
+    Callable<Date> cd = Date::new;
+    Factory<?, String> factory = Date::new;
+
+The following are supported:
+* Bound instance methods _(`c`)_
+* Unbound instance methods _(`listener`)_
+* Static methods _(`runnable`)_
+* Constructors _(`cd` and `factory`)
+
+The resulting Java 7 code for these statements is:
+
+    Callable<String> c = (new Callable<String>() { 
+        public String call() throws java.lang.Exception { return this.toString(); }
+    });
+    ChangeListener listener = (new ChangeListener() {
+        public void stateChanged(javax.swing.event.ChangeEvent arg0) { arg0.toString(); }
+    });
+    Runnable runnable = (new Runnable() {
+      public void run() { MyClass.execute(); }
+    });
+    Callable<Date> cd = (new Callable<Date>() {
+      public Date call() throws java.lang.Exception { return new java.util.Date(); }
+    });
+    Factory<?, String> factory = (new Factory<Object, String>() {
+      public Object create(String arg) { return new java.util.Date(arg); }
+    });
+
 --------------------------
 
 ### Other lambda expressions
 Lambda expressions outside of a variable declaration are not supported, but will be in the future.
 
-### Method and Constructor references
-Method references and constructor references are not yet supported, but will be in the future.
-
+### Other Method and Constructor references
+Method references and constructor references outside of a variable declaration are not supported, but will be in the future.
 
 Unlikely to be Supported Features
 ---------------------------------