Is there something equivalent for StaticClass::new
for inner class given the outer class instance?
Edit:
I.e. if I have
class Outer {
class Inner {
}
}
I can do Outer o = new Outer(); Inner i = o.new Inner()
in old Java. How can I express the o.new Inner()
as function reference.
According to the Oracle tutorials, there are four kinds of method references:
ContainingClass::staticMethodName
containingObject::instanceMethodName
ContainingType::methodName
ClassName::new
References to a local/nested class are not listed, so I would assume it's not supported.
You can use the java.util.function.Supplier
to trigger the usage of lambdas in order to obtain an instance of the nested class:
Outer outer = new Outer();
Supplier<Outer.Inner> supplier = () -> outer.new Inner();
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments