Marc Knaup
05/10/2019, 1:47 PMenum
type (instead of enum class
) then please don't do that 🙏marstran
05/10/2019, 1:49 PMMarc Knaup
05/10/2019, 1:54 PMMarc Knaup
05/10/2019, 1:54 PMenum class
to be more specific.marstran
05/10/2019, 1:55 PMMarc Knaup
05/10/2019, 1:56 PMMarc Knaup
05/10/2019, 1:56 PMenum class
there could be a non-class enum
in the future 😄marstran
05/10/2019, 1:57 PMMarc Knaup
05/10/2019, 1:58 PMmarstran
05/10/2019, 2:02 PMMarc Knaup
05/10/2019, 2:10 PMordinal
, name
, valueOf
, Comparable
(and maybe others) defined by default which is not desirable.
• it has a recursively generic abstract superclass.
A String would be a reference type again, including related overhead.
In memory it could be an primitive int, a memory address or whatever - I don't care nor need to know as a developer. Similar to inline classes and properly implemented in the JVM with project Valhalla.Marc Knaup
05/10/2019, 2:11 PMr4zzz4k
05/10/2019, 2:22 PMComparable
is expected on these or not, but regarding primitives and enums you can check this: https://youtrack.jetbrains.com/issue/KT-23823Ruckus
05/10/2019, 2:31 PMRuckus
05/10/2019, 2:33 PMfun log(level: Level, message: String) {
if (level > threshold) ...
}
Ruckus
05/10/2019, 2:38 PMMarc Knaup
05/10/2019, 2:55 PMMarc Knaup
05/10/2019, 2:56 PMRuckus
05/10/2019, 3:15 PMto ascertain the number of; to specify one after another
An enumeration is a complete, ordered listing of all the items in a collection.
Marc Knaup
05/10/2019, 3:26 PMRuckus
05/10/2019, 3:28 PMMarc Knaup
05/10/2019, 3:31 PMlistOf(2, 1)
1 comes after 2 its not automatically greater than 2.Marc Knaup
05/10/2019, 3:31 PMRuckus
05/10/2019, 3:36 PMMarc Knaup
05/10/2019, 3:36 PMRuckus
05/10/2019, 3:37 PMRuckus
05/10/2019, 3:40 PMMarc Knaup
05/10/2019, 3:43 PMjeremy
05/10/2019, 3:47 PMjeremy
05/10/2019, 3:47 PMMarc Knaup
05/10/2019, 3:50 PMRuckus
05/10/2019, 3:50 PMsealed class
). If it doesn't make sense to say South comes after North, it doesn't make sense to enumerate it.Marc Knaup
05/10/2019, 3:52 PMMarc Knaup
05/10/2019, 3:54 PMRuckus
05/10/2019, 3:54 PMRuckus
05/10/2019, 3:55 PMMarc Knaup
05/10/2019, 3:56 PMenum class
in Kotlin works the way it does is that it needed Java compatibility.
I just suggest rethinking it as Kotlin becomes more and more its own language.Ruckus
05/10/2019, 4:00 PMAny
doesn't implement the same API as Java's object
. I would counter that enum class
in Kotlin works the way it does because it makes sense. That's why most every language with enums does that, even if they never talk to Java or C or whatever.Marc Knaup
05/10/2019, 4:03 PMMarc Knaup
05/10/2019, 4:03 PMRuckus
05/10/2019, 4:05 PMMarc Knaup
05/10/2019, 4:07 PMRuckus
05/10/2019, 4:11 PMRuckus
05/10/2019, 4:11 PMMarc Knaup
05/10/2019, 4:14 PMMarc Knaup
05/10/2019, 4:15 PMname
because it refers to Java/Kotlin identifier (the enum case) instead of the name of the thing the enum case actually describesRuckus
05/10/2019, 4:15 PMMarc Knaup
05/10/2019, 4:16 PMRuckus
05/10/2019, 4:16 PMname
is completely orthoganal to the comparability discussion.Marc Knaup
05/10/2019, 4:16 PMMarc Knaup
05/10/2019, 4:17 PMRuckus
05/10/2019, 4:17 PMCharSequence
CharSequence
is comparableRuckus
05/10/2019, 4:19 PMMarc Knaup
05/10/2019, 4:19 PMRuckus
05/10/2019, 4:19 PMMarc Knaup
05/10/2019, 4:20 PMRuckus
05/10/2019, 4:20 PMMarc Knaup
05/10/2019, 4:22 PMMarc Knaup
05/10/2019, 4:22 PMMarc Knaup
05/10/2019, 4:23 PMlouiscad
05/10/2019, 4:42 PMenum
.
That said, what you are looking for is sealed class
of `object`s, with explicit inlining where the ordinal used for the underlying constant primitive is explicitly specified but private to the declaration, so it can be used for public APIs without unexpected breakages.
We could also imagine a set class
that would be like a one level sealed class
with stateless objects only, where either order would matter, or explicit ordinal would be specified, so the compiler flattens it to primitive values for the produced binary.
It could also work with something like R8 or proguard with a Kotlin specific logic to inline down to primitive all fully stateless object
based `sealed class`es.
Are you targetting Android?Marc Knaup
05/10/2019, 4:44 PMMarc Knaup
05/10/2019, 4:47 PMDico
05/10/2019, 9:18 PMenum class
, each of which have their use cases, you should consider using another way of declaring it.louiscad
05/11/2019, 7:59 PMDico
05/11/2019, 8:14 PMMarc Knaup
05/12/2019, 11:27 AMDico
05/12/2019, 11:40 AMMarc Knaup
05/12/2019, 11:42 AMMarc Knaup
05/12/2019, 11:42 AMDico
05/12/2019, 11:43 AMMarc Knaup
05/12/2019, 11:44 AMDico
05/12/2019, 11:45 AMMarc Knaup
05/12/2019, 11:46 AMDico
05/12/2019, 11:46 AMlouiscad
05/12/2019, 11:46 AMsealed class
. There's even an IDE intention to do the conversion in no time.Marc Knaup
05/12/2019, 11:46 AMlouiscad
05/12/2019, 11:48 AMMarc Knaup
05/12/2019, 11:48 AMlouiscad
05/12/2019, 11:50 AMMarc Knaup
05/12/2019, 11:52 AMlouiscad
05/12/2019, 11:52 AMMarc Knaup
05/12/2019, 11:54 AMlouiscad
05/12/2019, 11:55 AMString
, but not an enum of String
, this doesn't make sense and is impossible. The name of the enum entry though, is a String
, and you can also retrieve it.louiscad
05/12/2019, 11:55 AMMarc Knaup
05/12/2019, 11:55 AMMarc Knaup
05/12/2019, 11:56 AMMarc Knaup
05/12/2019, 11:57 AMlouiscad
05/12/2019, 11:58 AMenum class
.louiscad
05/12/2019, 12:00 PMMarc Knaup
05/12/2019, 12:00 PMlouiscad
05/12/2019, 12:01 PMMarc Knaup
05/12/2019, 12:01 PMMarc Knaup
05/12/2019, 12:03 PMlouiscad
05/12/2019, 12:05 PMMarc Knaup
05/12/2019, 12:11 PMDico
05/12/2019, 1:45 PMlouiscad
05/12/2019, 2:10 PMallCases
property defined later on.
2. To have something like `sealed class`es, they use the keyword indirect
to have an enum case be another enum, which reads harder than it should be IMHO.
3. Their "enums" are really just a set/group of values that enables genuinely cool syntax in `switch`es and the related compiler checks, and you can make them use any primitive value, be it a Character
, a Float
, etc.
Consequently, I think we're good in Kotlin with `sealed class`es, Java's and Kotlin enums are more accurate to the English definition of enumeration with their comparability, ordinals and names, and are also simpler although less full featured than Swift's fake enums.
I'm not against something like in Swift as kind of a middle ground between `sealed class`es and `enum class`es, but I don't want them to be referred as enumerations. `set class`es is one of the naming I have in mind. If you think such a thing should be introduced in Kotlin because you have or can find use cases for it that current options don't satisfy well, then starting to work on a KEEP would be sound thing to do.gildor
05/14/2019, 7:09 AMkind of a middle ground between `sealed class`es andoh, please, no need to add new entities to the language, some people already confused what to choose enum or sealed classenum class