Skip to main content

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 class Util{ public static String capitalize(String text){ return text.toUpperCase();} } //Kotlin class Util { companion object { @JvmStatic fun capitalize(text:String): String { return text.toUpperCase() } } } 

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() } } } 

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 class Util{ public static String capitalize(String text){ return text.toUpperCase();} } //Kotlin class Util { companion object { @JvmStatic fun capitalize(text:String): String { return text.toUpperCase() } } } 

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() } } } 
Source Link

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 class Util{ public static String capitalize(String text){ return text.toUpperCase();} } //Kotlin class Util { companion object { @JvmStatic fun capitalize(text:String): String { return text.toUpperCase() } } }