https://kotlinlang.org logo
#getting-started
Title
# getting-started
n

nbento.neves

08/12/2022, 9:17 AM
Hi, I saw a
kt
file with an
object
inside an
object
. I would like to know if someone can help me to understand the difference between using the
object
and a
companion object
. Is this the right way to use
object
?
Copy code
object Type {
    object USER {
        const val KEY  = "key"
        const val NAME  = "name"
    }
}
a

Alessandro Ciccimarra

08/12/2022, 9:36 AM
Hi Nuno, your example looks OK to me as a way of using `object`s to organise constant values, so that you can easily access them using IDE autocompletion as
Type.User.KEY
. Details about
object
declarations can be found here.
👀 1
n

nbento.neves

08/12/2022, 10:18 AM
Thanks 🙂
👍🏼 1
2 Views