TheTechWolf
TheTechWolf

Reputation: 2144

How to call from Java Kotlin method which is named with escape characters?

How this Kotlin function should be called from Java?

fun `some random function name`(){

}

Upvotes: 2

Views: 715

Answers (1)

hotkey
hotkey

Reputation: 147991

Java provides no character escaping in identifiers. You can only do that using Java reflection:

Kotlin:

class MyClass {
    fun `some random function name`() { }
}

Java:

MyClass c = new MyClass();
c.getClass().getMethod("some random function name").invoke(c);

Or cache the Method returned from the getMethod() call. Or use method handles.

Upvotes: 6

Related Questions