What is the equivalent of Java static methods in Kotlin?

前端 未结 28 1212
眼角桃花
眼角桃花 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 09:45

    This also worked for me

    object Bell {
        @JvmStatic
        fun ring() { }
    }
    

    from Kotlin

    Bell.ring()
    

    from Java

    Bell.ring()
    

提交回复
热议问题