There is no static
keyword in Kotlin.
What is the best way to represent a static
Java method in Kotlin?
The exact conversion of the java static method to kotlin equivalent would be like this. e.g. Here the util class has one static method which would be equivalent in both java and kotlin. The use of @JvmStatic is important.
Java code:
class Util{
public static String capitalize(String text){
return text.toUpperCase();}
}
Kotlin code:
class Util {
companion object {
@JvmStatic
fun capitalize(text:String): String {
return text.toUpperCase()
}
}
}