https://kotlinlang.org logo
Title
d

Dominaezzz

02/15/2019, 7:04 PM
What's the best I can get to an enum entry alias?
I guess an inline extension property.
e

elect

02/16/2019, 7:15 AM
What do you mean by enum entry alias?
d

Dominaezzz

02/16/2019, 10:47 AM
enum class SomeEnum {
    A, B, C
}

// Current solution
inline val SomeEnum.Companion.A_OLD: SomeEnum get() = SomeEnum.A

// Thus allowing deprecation/renaming of A_OLD to A
SomeEnum.A // Works
SomeEnum.A_OLD // Also works, even though it's not defined inside enum.
d

Dico

02/16/2019, 3:34 PM
I dont believe that's binary compatible
d

Dominaezzz

02/16/2019, 3:36 PM
Yeah, it's not. I'm considering just having both inside the enum.
d

Dico

02/16/2019, 3:46 PM
You should probably add
@Deprecated
to the old thing, wherever you put it
Its effective because you can make code not compile against your new version by doing this without giving up binary compatibility
d

Dominaezzz

02/16/2019, 3:52 PM
The enum has a
val value: UInt
property, both
A
and
A_OLD
have the same
value
and I was hoping to make them point to the same entry instead of just having the same
value
.
For my use case it's not for deprecation, it's literally just an alternative name for the entry.
d

Dico

02/16/2019, 4:08 PM
Unfortunately, you cannot override
equals
in enums.
d

Dominaezzz

02/16/2019, 4:10 PM
Maybe a sealed class instead?
d

Dico

02/16/2019, 4:11 PM
You could go with simple properties?
d

Dominaezzz

02/16/2019, 4:13 PM
Yes. It's only to provide type-safe enums for Vulkan or OpenGL. Anything better than loose global integers will do the trick tbh.
d

Dico

02/16/2019, 4:17 PM
Ah, I've done some of that as well
I just use enums though, I'm not concerned if constants are the same
d

Dominaezzz

02/16/2019, 4:23 PM
That would be fine if the enums were only used as inputs but in some cases the api returns an enum to the application (as an Int) and my wrapper has to look up the correct enum entry. Equality would have to work if the user needs to do anything with the enum value.