isOptional is a Kotlin reflection property on KParameter. It is true when a callable parameter has a default value and may be omitted from a callBy argument map. section 12.2.5
Checking which constructor arguments may be omitted
private fun ensureAllParametersPresent(arguments: Map<KParameter, Any?>) { for (param in constructor.parameters) { if (arguments[param] == null && !param.isOptional && !param.type.isMarkedNullable) { throw JKidException("Missing value for parameter ${param.name}") } } } section 12.2.5
Use isOptional to distinguish constructor parameters during reflective deserialization:
- Omit an argument when isOptional is true; the callable supplies its default value. section 12.2.5
- Supply null for a parameter whose type is nullable when no value is present. section 12.2.5
interface KCallable<out R> {
fun callBy(args: Map<KParameter, Any?>): R
// ...
}
KCallable.callBy accepts a map keyed by KParameter, providing the reflective call mechanism where optional parameters can be omitted. section 12.2.5
