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

Cannot fix covariant return of an interface #753

Open
jpobst opened this issue Dec 3, 2020 · 0 comments
Open

Cannot fix covariant return of an interface #753

jpobst opened this issue Dec 3, 2020 · 0 comments
Labels
bug Component does not function as intended generator Issues binding a Java library (generator, class-parse, etc.)

Comments

@jpobst
Copy link
Contributor

jpobst commented Dec 3, 2020

Context: xamarin/GooglePlayServicesComponents#404

Given this construct:

public interface IProvider {
  Java.Lang.Object Get ();
}

public class ProviderOfLazy : IProvider {
  public ILazy Get () { ... }
}

Initially you will get an error that this doesn't count as the implementation because of covariant return types.

If you try to do the usual fix of changing ProviderOfLazy.Get to return JLO, then you get a different error because ILazy in an interface, which does not inherit JLO:

return global::Java.Lang.Object.GetObject<global::Com.Google.Firebase.Inappmessaging.Dagger.ILazy> 
(__rm.Handle, JniHandleOwnership.TransferLocalRef);
error CS0266: Cannot implicitly convert type 'Com.Google.Firebase.Inappmessaging.Dagger.ILazy' to 
'Java.Lang.Object'. An explicit conversion exists (are you missing a cast?)

This could potentially be fixed by casting to JLO, since we "know" the object will be a JLO.

return (Java.Lang.Object) global::Java.Lang.Object.GetObject
<global::Com.Google.Firebase.Inappmessaging.Dagger.ILazy> 
(__rm.Handle, JniHandleOwnership.TransferLocalRef);
@jpobst jpobst added bug Component does not function as intended generator Issues binding a Java library (generator, class-parse, etc.) labels Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Component does not function as intended generator Issues binding a Java library (generator, class-parse, etc.)
Projects
None yet
Development

No branches or pull requests

1 participant