Skip to content

Handle Kotlin name-mangled methods #534

@jpobst

Description

@jpobst

Related: #525

There are cases where Kotlin generates Java methods that are not allowed Java identifier names:

public void foo-WZ4Q5Ns(int) { }

We already change the name to Foo () so C# can compile the method, and JNI allows us to call the method correctly. However we cannot allow the user to override this method because we cannot create the Java override in the JCW. There are several cases where this comes up.

Virtual Method

public void foo-WZ4Q5Ns(int) { }

In this case we need to:

  • Mark the method as non-virtual to prevent the user from overriding it.

Abstract / Interface Method

abstract class Bar {
    abstract void foo-WZ4Q5Ns(int);
}

interface IBar {
    void foo-WZ4Q5Ns(int);
}

In this case we cannot allow the user to implement the class as the mangled method cannot be implemented. We still need the class to be bound because there might be a Kotlin-created subclass
that needs the base class to exist.

There's no foolproof way to mark these as "not implementable". The best we can do for now is to detect if the user implements them in GenerateJavaStubs and give an informative error at that point.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions