I was switching from Java to kotlin for Android Devlopment. When I searched about equivalent of Java static methods in Kotlin, I found that companion object is. But the problem is while creating more than one static methods in kotlin. I get these errors only one companion object is allowed per class.
You can put multiple methods and properties inside an object. They're just like classes, but they have a single instance.
class A {
companion object {
fun a() {}
fun b() {}
val x = 42
var y = "foo"
}
}
If you can set it as
class C {
companion object {
@JvmStatic fun foo() {}
fun bar() {}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With