What is the equivalent of Java static methods in Kotlin?

前端 未结 28 1134
眼角桃花
眼角桃花 2020-11-27 09:03

There is no static keyword in Kotlin.

What is the best way to represent a static Java method in Kotlin?

28条回答
  •  执念已碎
    2020-11-27 10:04

    All static member and function should be inside companion block

      companion object {
        @JvmStatic
        fun main(args: Array) {
        }
    
        fun staticMethod() {
        }
      }
    

提交回复
热议问题