Join Slack
why doesn't L13 work ?
# getting-started
l
LastExceed
02/09/2022, 12:53 PM
why doesn't L13 work ?
Untitled.kt
s
Sam
02/09/2022, 12:56 PM
The
values()
method on an enum isn't actually a member of its companion object. (If it was, you wouldn't be able to define a new companion object, because there would already be one).
Sam
02/09/2022, 12:56 PM
The
docs
describe it as a "synthetic method"
Sam
02/09/2022, 12:59 PM
I think you actually can define your own
values()
method in the companion object, but it won't override the built-in one.
MyEnum.values()
will always resolve to the built-in method and will ignore the one in the companion object.
Sam
02/09/2022, 1:01 PM
I'm guessing that
KT-11968
will provide a route to resolve this oddity in the language design, which presumably stems from Java interop
l
LastExceed
02/09/2022, 1:34 PM
thanks
s
Sam
02/09/2022, 1:35 PM
No problem, sorry it's not a more satisfying explanation
Sam
02/09/2022, 1:36 PM
This is definitely one of Kotlin's rough edges
8
Views
Open in Slack
Previous
Next
kotlinlang
A modern programming language that makes developers happier.
Powered by