Skip to content

Commit 809e27a

Browse files
committed
Constructor Reference
1 parent 96623f2 commit 809e27a

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.learn.constructorreference;
2+
3+
import com.learn.data.Student;
4+
5+
import java.util.function.Supplier;
6+
7+
public class ConstructorReferenceExample {
8+
9+
/**
10+
* Calls No-arg Constructor
11+
*/
12+
static Supplier<Student> studentSupplier = Student::new;
13+
14+
public static void main(String[] args) {
15+
16+
/**
17+
* Create new Object of Student with default values
18+
*/
19+
System.out.println(studentSupplier.get());
20+
}
21+
}

Modern-Java-Examples/src/com/learn/data/Student.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public Student(String name, int gradeLevel, String gender, double gpa, List<Stri
1818
this.activities = activities;
1919
}
2020

21+
public Student() {
22+
23+
}
24+
2125
public String getName() {
2226
return name;
2327
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This repository contains the basic &amp; advance level examples related to Java
1919
* [Method Reference](Modern-Java-Examples/src/com/learn/methodreference/FunctionMethodReferenceExample.java)
2020
* [Consumer Method Reference](Modern-Java-Examples/src/com/learn/methodreference/ConsumerMethodReferenceExample.java)
2121
* [Refactoring Method Reference](Modern-Java-Examples/src/com/learn/methodreference/RefactorMethodReferenceExample.java)
22+
* [Constructor Reference](Modern-Java-Examples/src/com/learn/constructorreference/ConstructorReferenceExample.java)
2223

2324

2425

0 commit comments

Comments
 (0)