java.interop icon indicating copy to clipboard operation
java.interop copied to clipboard

Containing type does not implement interface

Open mattleibow opened this issue 4 years ago • 3 comments

I have a simple case of abstract classes that aren't generating the correct code.

Java: interface-tests.jar.zip

public abstract class AbstractCollection extends Object implements Collection {
    // required implementation
}
public abstract class AbstractSet extends AbstractCollection implements Set {
}

I create a binding project, but I get some errors:

obj/Debug/generated/src/Interfacestests.AbstractSet.cs(68,33,68,55): error CS0540: 'AbstractSetInvoker.ISet.AddAll(ICollection)': containing type does not implement interface 'ISet'
obj/Debug/generated/src/Interfacestests.AbstractSet.cs(82,33,82,55): error CS0540: 'AbstractSetInvoker.ISet.ContainsAll(ICollection)': containing type does not implement interface 'ISet'
obj/Debug/generated/src/Interfacestests.AbstractSet.cs(96,33,96,55): error CS0540: 'AbstractSetInvoker.ISet.RemoveAll(ICollection)': containing type does not implement interface 'ISet'
obj/Debug/generated/src/Interfacestests.AbstractSet.cs(110,33,110,55): error CS0540: 'AbstractSetInvoker.ISet.RetainAll(ICollection)': containing type does not implement interface 'ISet'

I can fix this by creating a partial class and adding the interface, but that seems like it should have worked?

partial class AbstractSetInvoker : Java.Util.ISet {
}

mattleibow avatar Aug 14 '19 22:08 mattleibow

I think this is the same as: https://github.com/xamarin/java.interop/issues/503

jpobst avatar Oct 31 '19 15:10 jpobst

Related to this: https://github.com/xamarin/java.interop/issues/359#issuecomment-628722931

mattleibow avatar Aug 31 '20 21:08 mattleibow

Notes:

We are generating:

public abstract partial class AbstractSet : global::Interfacestests.AbstractCollection, global::Java.Util.ISet
{
  // No generated methods
}

internal partial class AbstractSetInvoker : AbstractSet
{
  unsafe global::System.Boolean global::Java.Util.ISet.AddAll (global::System.Collections.ICollection c) { ... }
  unsafe global::System.Boolean global::Java.Util.ISet.ContainsAll (global::System.Collections.ICollection c) { ... }
  unsafe global::System.Boolean global::Java.Util.ISet.RemoveAll (global::System.Collections.ICollection c) { ... }
  unsafe global::System.Boolean global::Java.Util.ISet.RetainAll (global::System.Collections.ICollection c) { ... }
}

AbstractSet does not generate any methods because Java.Lang.ISet has the same contract as Java.Lang.ICollection which is implemented by AbstractCollection.

I think the correct fix is to not generate the explicitly implemented methods in AbstractSetInvoker. Removing them also allows the compilation to succeed.

jpobst avatar May 13 '21 14:05 jpobst