How to implement a constructor reference with one or more arguments in Java | Constructor reference

preview_player
Показать описание

A method reference can also be applicable to constructors in Java 8. A constructor reference can be created using the class name and a new keyword. The constructor reference can be assigned to any functional interface reference that defines a method compatible with the constructor.

In this video, we will talk about method reference using the constructor.
How to implement a constructor reference with one or more arguments in Java

You can access the following full courses in Udemy, if you need coupons inbox me
********************************************************************************

********************************************************************************
Like , Share and leave us your comments
********************************************************************************
Thanks For Watching !!!
********************************************************************************
Рекомендации по теме
Комментарии
Автор

What if I use constructor reference with generics? Why does
l = ArrayList<>::new; have error?

But if I use lambda expression, l = ()-> new ArrayList<>();
this is okay. Why?

public class Test{



public static void main(String... args){

Supplier<ArrayList>

l = ()-> new ArrayList(); // good

l = ()-> new ArrayList<>(); // good

l = ()-> new ArrayList<Integer>(); // good

l = ArrayList<Integer>::new; // good

l = ArrayList::new; // good

l = ArrayList<>::new; // Error, why?



}

}

HenryLeu