Java 8 Supplier with arguments in the constructor

后端 未结 8 1961
小蘑菇
小蘑菇 2020-12-01 00:07

Why do suppliers only support no-arg constructors?

If the default constructor is present, I can do this:

create(Foo::new)

But if th

8条回答
  •  粉色の甜心
    2020-12-01 00:29

    But, a 1-arg constructor for T that takes a String is compatible with Function:

    Function fooSupplier = Foo::new;
    

    Which constructor is selected is treated as an overload selection problem, based on the shape of the target type.

提交回复
热议问题