Click here to watch in Youtube :
https://www.youtube.com/watch?v=AEywwBHNllo&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
How to refer a constructor using method reference | Method reference in Java 8 |
/** * * We are using functional interface Messageable and referring constructor with * the help of functional interface. * */ @FunctionalInterface interface Messageable { Message getMessage(String msg); } class Message { public Message(String msg) { System.out.print(msg); } } public class MethodReferenceDemo { public static void main(String[] args) { Messageable messageable = Message::new; messageable.getMessage("Hello"); } }Output
HelloClick the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/LambdaDemo_method_ref_constructor_app.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/LambdaDemo_method_ref_constructor_app
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/525432e9afa25ee5052810cb2318f64453ffeffa/BasicJava/LambdaDemo_method_ref_constructor_app/?at=master
See also:
No comments:
Post a Comment