Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[generator] Qualify Java.Lang.Object.Handle references #38

Merged
merged 1 commit into from
May 30, 2016

Commits on May 27, 2016

  1. [generator] Qualify Java.Lang.Object.Handle references

    Android N Preview 2 adds some methods named `handle()`, such as
    `java.util.concurrent.CompletableFuture.handle()`. This clashes with
    the Java.Lang.Object.Handle property, resulting in C# compiler errors
    within the generated binding code:
    
    	if (Handle != IntPtr.Zero)
    	// Java.Util.Concurrent.CompletableFuture.cs(101,8): error CS0019: Operator `!=' cannot be applied to operands of type `method group' and `System.IntPtr'
    
    	__args [0] = new JniArgumentValue ((other == null) ? IntPtr.Zero : other.Handle);
    	// Java.Util.Concurrent.CompletableFuture.cs(254,65): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between `System.IntPtr' and `method group'
    
    There are two possible fixes:
    
    1. Forbid the name `Handle`, and *rename* any occurrences to something
        else, such as `InvokeHandle`.
    
    2. *Qualify* the `Java.Lang.Object.Handle` property reference.
    
    (1) is kinda ugly.
    
    (2) is possible by using a cast: instead of `value.Handle`, use e.g.
    `((Java.Lang.Object) value).Handle`, which causes the compiler to use
    the intended member, and not whatever may be hiding it in the current
    scope.
    
    (2) results in an arguably nicer API -- maybe? -- as the bound API
    more closely mirrors the Java API.
    
    (2) also results in uglier binding code. However, who reads it?
    
    Note: Why cast to e.g. Java.Lang.Object and not IJavaObject? To avoid
    virtual calls. `((Java.Lang.Object)value).Handle` results in a direct
    invocation of the Object.get_Handle() method, avoiding a virtual call.
    Casting to IJavaObject would result in a virtual interface method
    invocation, causing additional runtime overhead to lookup the value.
    jonpryor committed May 27, 2016
    Configuration menu
    Copy the full SHA
    e265800 View commit details
    Browse the repository at this point in the history