Java 8 — Constructor Reference | Code Factory

package com.codeFactory.methodAndConstructorReference;class Sample {
Sample() {
System.out.println("Sample.Sample()");
}
}
interface Interf {
public Sample get();
}
// Using Lambda Expression
public class Test {
public static void main(String... args) {
Interf i = () -> {
return new Sample();
};
Sample s = i.get();
}
}
// Using Constructor Reference
public class Test {
public static void main(String... args) {
Interf i = Sample::new;
Sample s = i.get();
}
}
Sample.Sample()
  • classname :: new
  • e.g. Sample :: new

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Java Lambdas…..

Eventador Streams Podcast: A Primer for Apache Beam on Flink with Maximilian Michels

iOS CitySpire App’s Development

Time to Show the Product

Doing some “home automation” with Google Calendar, Todoist and Microsoft Flow

How a Retail Mobile App Can Be Impactful to Your Business

Getting to know Spring Boot Application

Improving App Performance with Baseline Profiles

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Code Factory

Code Factory

More from Medium

Responsibility Driven Object Oriented Design

Singleton Design Pattern in Java

Exception Handling in Java

Java Post — Immutable Strings