You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently to access a feature's default option you need one of its existing options, e.g.
AuthType.Retina.defaultOption
where the Retina part is only misleading because it's irrelevant — defaultOption could return AuthType.Fingerprint.
I'd prefer to access it "statically" to avoid hardcoding the irrelevant option e.g.
AuthType.defaultOption
There is a workaround, but it has the disadvantage of being a top-level function instead of being accessible through a feature:
inlinefun <reifiedT> defaultOption(): T where T : Feature<T>, T : Enum<T> =
enumValues<T>().first().defaultOption
val default = defaultOption<AuthType>()
Any design considerations I could be missing here?
The text was updated successfully, but these errors were encountered:
AlexKrupa
changed the title
Expose Feature.defaultOption through its companion object
Expose Feature.defaultOption "statically" through companion objectApr 14, 2023
There is no way to require it in a contract. Classes cannot be forced to have a companion object, so it cannot be provided in the base library. This could only be done via code generation as a "bonus". But I wouldn't want to have it in the core generator engine. I could imagine a feature for others to hook into generation process to modify the output as they wish. But ATM this seems like an overkill for this simple feature request.
There is an extension on Class<Feature<T>>, which allows you to use it like this YourFeature::class.java.defaultOption. You can shorten it to KClass with an extension wrapper.
Currently to access a feature's default option you need one of its existing options, e.g.
where the
Retina
part is only misleading because it's irrelevant —defaultOption
could returnAuthType.Fingerprint
.I'd prefer to access it "statically" to avoid hardcoding the irrelevant option e.g.
AuthType.defaultOption
There is a workaround, but it has the disadvantage of being a top-level function instead of being accessible through a feature:
Any design considerations I could be missing here?
The text was updated successfully, but these errors were encountered: