I know i can use constructor reference as hihger-order method's argument like this:
collection.stream().map(MyClass::new);
But I have MyClass
as a variable Class<MyClass> clazz = MyClass.class
. Can I use it to pass constructor reference to .map(Function)
method? I want to do something like this, is there a way to do it?
Class<MyClass> clazz = MyClass.class;
collection.stream().map(clazz.getConstructor())
Aucun commentaire:
Enregistrer un commentaire