Accessing Kotlin extension functions from Java

前端 未结 9 1096
梦毁少年i
梦毁少年i 2020-11-29 21:27

Is it possible to access extension functions from Java code?

I defined the extension function in a Kotlin file.

package com.test.extensions

import c         


        
9条回答
  •  孤街浪徒
    2020-11-29 21:43

    It works for me:

    Kotlin

    Java code

    My project is an old android project created with Java; now I created the first kotlin file and added String extensions fun String.isNotNullOrEmpty(): Boolean {... }

    and I could call it from java file using: StringUtilsKt.isNotNullOrEmpty(thestring).

    My kotlin file name is StringUtils

提交回复
热议问题