diff options
author | Dimitri Kokkonis <kokkonisd@gmail.com> | 2019-08-06 12:40:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-06 12:40:31 +0200 |
commit | 922fc494bcce6cb53d80a5c2c9c039a480c82c1f (patch) | |
tree | a62b6e194db73630bfed43301b1c130d52f9dbba /kotlin.html.markdown | |
parent | 5710394756a426255d2dc81d2d342e9786ac2c1b (diff) | |
parent | 2f0b904f6ffe68d15fedf7e50a3a64e1a47a9145 (diff) |
Merge pull request #1 from adambard/master
Update fork
Diffstat (limited to 'kotlin.html.markdown')
-rw-r--r-- | kotlin.html.markdown | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/kotlin.html.markdown b/kotlin.html.markdown index 9336d217..5bbf6847 100644 --- a/kotlin.html.markdown +++ b/kotlin.html.markdown @@ -350,11 +350,22 @@ fun helloWorld(val name : String) { // Enum classes are similar to Java enum types. enum class EnumExample { - A, B, C + A, B, C // Enum constants are separated with commas. } - fun printEnum() = println(EnumExample.A) // => A +// Since each enum is an instance of the enum class, they can be initialized as: +enum class EnumExample(val value: Int) { + A(value = 1), + B(value = 2), + C(value = 3) +} +fun printProperty() = println(EnumExample.A.value) // => 1 + +// Every enum has properties to obtain its name and ordinal(position) in the enum class declaration: +fun printName() = println(EnumExample.A.name) // => A +fun printPosition() = println(EnumExample.A.ordinal) // => 0 + /* The "object" keyword can be used to create singleton objects. We cannot instantiate it but we can refer to its unique instance by its name. |