Open
Description
Imagine we have the following Java:
public abstract class ClassA {
protected abstract class ChildClass {
public abstract ClassA createThing ();
}
}
public class ClassB extends ClassA {
public class ChildClass extends ClassA.ChildClass {
@Override
public ClassB createThing () { ... }
}
}
There are 2 interesting things to "fix" when translating this to C#:
public
classClassB.ChildClass
inheritsprotected
classClassA.ChildClass
, which C# doesn't allowClassB.ChildClass.createThing ()
implements theabstract
methodClassA.ChildClass.createThing ()
, but it has a covariant return type
The way we fix (1) is:
- Make
ClassB.ChildClass
inherit fromObject
instead ofClassA.ChildClass
- Copy members from
ClassA.ChildClass
toClassB.ChildClass
If we didn't have the covariant return type (2), we would detect that ClassB.ChildClass.createThing ()
implements ClassA.ChildClass.createThing ()
and we would generate a virtual
method.
However, because of the covariant return type, we cannot make the match and end up generating both a virtual and an abstract createThing ()
:
public abstract partial class ClassA : Java.Lang.Object {
protected internal abstract partial class ChildClass : Java.Lang.Object {
[Register ("createThing", "()Lexample/ClassA;", "GetCreateThingHandler")]
public abstract ClassA CreateThing ();
}
}
public partial class ClassB : ClassA {
public new partial class ChildClass : Java.Lang.Object {
[Register ("createThing", "()Lexample/ClassB;", "GetCreateThingHandler")]
public virtual unsafe ClassB CreateThing () { ... }
[Register ("createThing", "()Lexample/ClassA;", "GetCreateThingHandler")]
public abstract ClassA CreateThing ();
}
}
This fails with:
CS0513 'ClassB.ChildClass.CreateThing()' is abstract but it is contained in non-abstract type
as well as several duplicate member errors.