IntentionallyRequiredParameterAfterOptional

annotation class IntentionallyRequiredParameterAfterOptional(val reason: ExemptionReason = ExemptionReason.OTHER, val description: String = "")(source)

Acknowledges that the annotated function or constructor deliberately declares a required parameter after optional ones.

The library-api-watchdog compiler plugin warns about publicly visible functions and constructors that declare a required parameter - one without a default value - after an optional (defaulted or vararg) parameter, because parameters should go from the general to the specific: essential inputs first, optional inputs last. A required parameter behind optional ones can't be passed positionally without re-stating the defaults in front of it. A required function-type (or fun interface) parameter in the last position is not reported: it keeps trailing-lambda call syntax available. Apply this annotation to suppress the warning when the order is intended (for example, when appending a parameter anywhere else would break existing users).

See the check documentation for rationale and examples.

Parameters

reason

why the parameter order is intended.

description

free-form explanation of the exemption. May be empty only when reason explains the exemption on its own (ExemptionReason.FOR_BACKWARDS_COMPATIBILITY, ExemptionReason.API_DESIGN).

Properties

Link copied to clipboard
Link copied to clipboard