Kotlin Public Static Final Field

October 21, 2018
class AlbumOrderType {
    companion object {
        const val OLDEST_FIRST = 1
        const val NEWEST_FIRST = 2
    }
}

val type = AlbumOrderType.OLDEST_FIRST

If you plan to use the code in Java

class AlbumOrderType {
    companion object {
        @JvmStatic val OLDEST_FIRST = 1
        @JvmStatic val NEWEST_FIRST = 2
    }
}

If you are using singleton object declaration.

object App {
    const val APP_NAME = "Hello"
}

val name = App.APP_NAME
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.