getNoArgConstructor abstract method
Retrieves the no-argument constructor of this Constructor instance, if available.
By default, only constructors with no parameters are considered.
However, if acceptWhenAllParametersAreOptional is set to true, then
constructors whose parameters are all optional will also be accepted.
Parameters
acceptWhenAllParametersAreOptional(default:false)
Iftrue, constructors where all parameters are optional will be returned even if they are not strictly "no-arg".
Returns
- A Constructor representing the no-arg constructor if one exists.
- Otherwise,
null.
Example
final clazz = Class<MyService>();
final ctor = clazz.getConstructors()
.getNoArgConstructor(true);
if (ctor != null) {
final instance = ctor.newInstance();
print("Created instance: $instance");
} else {
print("No suitable constructor found.");
}
Implementation
Constructor? getNoArgConstructor([bool acceptWhenAllParametersAreOptional = false]);