What is the equivalent of Java static methods in Kotlin?

前端 未结 28 1208
眼角桃花
眼角桃花 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:41

    For Java:

    public class Constants {
    public static final long MAX_CLICK_INTERVAL = 1000;}
    

    Equivalent Kotlin code:

    object  Constants {
    const val MAX_CLICK_INTERVAL: Long = 1000}
    

    So for the equivalent of Java static methods is object class in Kotlin.

提交回复
热议问题