What is the equivalent of Java static methods in Kotlin?

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

    There is no static keyword in kotlin. kotlin docs recommends to use package-level functions if u want to follow DRY. Create a file with .kt extension and put your method in it.

    package p
        fun m(){
        //fun body
        }
    

    after compilation m will have a signature of public static final void

    and

    import p.m
    

提交回复
热议问题