Java tutorial
import java.util.Objects; import java.util.function.Supplier; public class Main { public static My produce(Supplier<My> supp) { return supp.get(); } public static void main(String[] args) { My p1 = produce(() -> new My()); My p2 = produce(() -> new My()); System.out.println("Check the same object? " + Objects.equals(p1, p2)); } } class My { public My() { System.out.println("Sun Power initialized.."); } }