Method Reference

New Feature introduce in java 8 is Method Reference. Method reference is used to implement the method of functional interface from another class method. Only condition that Functional interface method and method which we are going to implement should have same signature and return type

Functional Interface

Functional interface is an interface which have only one abstract method.

In Blow Example Override the method of interface by using Implements Keyword

No alt text provided for this image

Same Example implemented Using Double colon operator

Assigned B class method implementation to A interface method without implementing A interface to class B(new B():: test)

No alt text provided for this image

We can use java Predefined methods also to implement the method of functional interface. In below example we used java predefined method println to implement method of interface A(System.out::println)

No alt text provided for this image













To view or add a comment, sign in

More articles by Rohit Chugh

  • Composite Key Property reader

    Problem Statement Java Properties class use to read the value of property defined in config file in key value pair. But…

    1 Comment

Insights from the community

Others also viewed

Explore topics