Skip to content

Cannot inherit java interface that covariantly overrides a method with Array return type #12407

Closed
scala/scala
#9650
@SrTobi

Description

@SrTobi

reproduction steps

using Scala 2.13.6,

Java:

public interface A {
    A[] getArray();
}

public interface B extends A {
    @Override
    B[] getArray();
}

Scala:

trait Test extends B

problem

When compiling the scala code the compiler gives:

incompatible type in overriding
def getArray(): Array[A] (defined in trait A)
  with def getArray(): Array[B] (defined in trait B);
 found   : (): Array[B]
 required: (): Array[A]
trait Test extends B

This makes it impossible to inherit B.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions