Kotlin static methods and static classes
static class
All methods are static methods, such as tool classes, constant pools, etc., directly replace the class before the class name with object
object Constants1 {
val text = "hello world!"
}
transfer
Constants1.text
static method
In Kotlin, static methods can be implemented as "companion objects". The specific operations are:
Inside the class wrap required static functions with companion object { }
class Constants {
companion object {
val text = "hello world!"
}
}
transfer
Constants.text