Method reference to a constructor

Referring a constructor can be done via the new keyword, as follows:

BiFunction<String, Integer, Melon> melonFactory = Melon::new;
Melon hemi1300 = melonFactory.apply("Hemi", 1300);

More details and examples about method reference to a constructor are available in the Implementing the factory pattern section in the previous chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset