objet compagnon kotlin
companion object{
const val DATA = "data"
}
Al Zaini Azharie
companion object{
const val DATA = "data"
}
class Test {
companion object {
var mInteger: Int = 10
fun hello() = println("hello world !")
}
}
fun main(args: Array<String>) {
print(Test.mInteger)
print(Test.hello())
}
class Person {
companion object Test {
fun callMe() = println("I'm called.")
}
}
fun main(args: Array<String>) {
Person.callMe()
}
class Person {
fun callMe() = println("I'm called.")
}
fun main(args: Array<String>) {
val p1 = Person()
// calling callMe() method using object p1
p1.callMe()
}