I am fairly new at kotlin. I know concepts of static member in java. According to documentation object works like static class / singleton but i cant seem to access them from my MainActivity. From examples, in kotlin i suppose do it as below but it seems not to be working for me. I am doing it wrong? I want to use object instead of companion object
TAG.kt
object TAG {
var MainActivity : String? = null
}
MainActivity.kt
class MainActivity : AppCompatActivity(){
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//Cannot find TAG.MainActivity as static variable like in Java
TAG.MainActivity = MainActivity::class.java.canonicalName as String
}
}
I have seen this posts but not working Static variables in kotlin?