Using Kotlin singleton from Java

nasch :

I've read up on this and everything I'm seeing says I should be able to do this so there must be some little thing I'm missing. I've converted a Java class to Kotlin:

object OrderTitle {
  @JvmOverloads
    fun generateMessage(context: Activity, otherParameter: AType? = null): AnotherType {
        // Do some things
   }
}

And I call it from Java:

message = OrderTitle.generateMessage(activity, property);

and get this error:

error: non-static method generateMessage(Activity,Property) cannot be referenced from a static context
Rene Ferrari :

Annotate your function with @JvmStatic so a real static java function is generated when compiling.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=85011&siteId=1