Skip to content

Conversation

@jpobst
Copy link
Contributor

@jpobst jpobst commented Dec 9, 2019

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.

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.

@jonpryor jonpryor merged commit 0065de4 into master Dec 9, 2019
@jonpryor jonpryor deleted the kotlin-fixups branch December 9, 2019 21:18
jonpryor pushed a commit that referenced this pull request Dec 10, 2019
Fixes: #534

There are cases where Kotlin generates Java methods that are invalid
Java identifiers:

	// Kotlin
	public open abstract class AbstractUnsigned {
	  public open fun foo(value : UInt) {
	    return 3u
	  }
	}

Results in Java bytecode:

	public abstract class example.AbstractUnsigned {
	  public abstract void foo-WZ4Q5Ns(int);
	  public example.AbstractUnsigned();
	}

`foo-WZ4Q5Ns` is not a valid Java identifier, due to the `-`.

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.

In this case, mark the method as *non*-`virtual` to prevent the
user from overriding it:

	// C#
	partial class AbstractUnsigned {
	  public void Foo(int value) …}
	}
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants