Java 8 Method Reference - Javatpoint
Java 8 Method Reference - Javatpoint
Globalization PaDners
Open
The Work-From-
Anywhere Model
Take Advantage of Remote
Employees and Work-From-
Anywhere Models to Hire Globally.
Globalization PaDners
Open
3. Reference to a constructor.
1) Reference to a Static
Method
Syntax
1. ContainingClass::staticMethodName
Example 1
interface Sayable{
void say();
sayable.say();
Test it Now
Output:
Example 2
System.out.println("Thread is running...");
t2.start();
Test it Now
Output:
Thread is running...
Example 3
import java.util.function.BiFunction;
class Arithmetic{
return a+b;
System.out.println(result);
Test it Now
Output:
30
Example 4
import java.util.function.BiFunction;
class Arithmetic{
return a+b;
return a+b;
return a+b;
System.out.println(result1);
System.out.println(result2);
System.out.println(result3);
Test it Now
Output:
30
30.0
30.0
2) Reference to an Instance
Method
like static methods, you can refer instance
methods also. In the following example,
we are describing the process of referring
the instance method.
Syntax
1. containingObject::instanceMethodName
Example 1
interface Sayable{
void say();
static method.");
InstanceMethodReference methodReference
// Referring non-
sayable.say();
// Referring non-
sayable2.say();
Test it Now
Output:
Example 2
t2.start();
Test it Now
Output:
Example 3
import java.util.function.BiFunction;
class Arithmetic{
return a+b;
System.out.println(result);
Test it Now
Output:
30
3) Reference to a Constructor
You can refer a constructor by using the
new keyword. Here, we are referring
constructor with the help of functional
interface.
Syntax
1. ClassName::new
Example
1. interface Messageable{
3. }
4. class Message{
5. Message(String msg){
6. System.out.print(msg);
7. }
8. }
2. hello.getMessage("Hello");
3. }
4. }
Test it Now
Output:
Hello
← Prev Next →
Feedback
Splunk SPSS
Swagger Transact-SQL
Tumblr ReactJS
Regex tutorial
Regex Reinforcement
Learning
RxJS tutorial
R Programming RxJS
Keras tutorial
Keras
Preparation
Aptitude
Aptitude Reasoning
Verbal Ability
Company
Questions
Trending Technologies
AWS Tutorial
Artificial AWS
Intelligence
Selenium tutorial
Hadoop ReactJS
Git Tutorial
Blockchain Git
DevOps Tutorial
B.Tech / MCA
DBMS tutorial
DAA tutorial
Computer Discrete
Organization Mathematics
html tutorial
Automata Tutorial
C++ tutorial
C Programming C++
Java tutorial
Java .Net
Python Programs
Data Warehouse
⇧ SCROLL TO TOP