Utils class in Kotlin

后端 未结 3 1286
暖寄归人
暖寄归人 2021-01-01 09:34

In Java, we can create an utilities class like this:

final class Utils {
    public static boolean foo() {
        return false;
    }
}

Bu

3条回答
  •  有刺的猬
    2021-01-01 09:46

    You'd need to use @JvmStatic for that:

    In Kotlin:

    object Utils {
        @JvmStatic
        fun foo(): Boolean = true
    }
    
    val test = Utils.foo()
    

    In Java:

    final boolean test = Utils.foo()
    

提交回复
热议问题