I have this Kotlin class:
class Storage {
companion object {
val COL_ID = "id"
}
}
and I want to use the COL_ID
in my Java code:
doSomething(Storage.COL_ID);
but, the compiler tells me that COL_ID
is private. I have tried to add public
to all the elements (class, object and val), but it has no effect.
How can I access these companion object constants?
Update I think my question is different from the given duplicate, because I want to create constants, instead of a static method.
I added const
, and everything was fine:
class Storage {
companion object {
const val COL_ID = "id"
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.