Hey guys, I am new in kotlin. I want to ask what i...
# android
k
Hey guys, I am new in kotlin. I want to ask what is the best way of doing declare const val.
Copy code
companion object {
   const val TABLE_USER_ATTRIBUTE_EMPID = "_id"
   const val TABLE_USER_ATTRIBUTE_DATA = "data"
}
vs
Copy code
object DbConstants {
    const val TABLE_USER_ATTRIBUTE_EMPID = "_id"
    const val TABLE_USER_ATTRIBUTE_DATA = "data"
}
which is one recommended way ?
j
Depends on scope IMO, If you have a class like
Database
and it was the best place to store the consts (e.g. cos it might be the only place it’s used), I’d use companion object in that class However if there’s no one place suited to store your constants , go with the second approach There really isn’t much different between the 2 approaches to be honest