Skip to content

Cannot override JavaClass that overrides method with omitted generics #24041

@SrTobi

Description

@SrTobi

Compiler version

3.7.3

Minimized code

JavaImpl.java

import java.lang.ref.Reference;

public abstract class JavaImpl implements Comparable<Reference<Object>> {
    @Override
    public int compareTo(Reference ref) { // <Object> is omitted
        return 0;
    }
}

ScalaImpl.scala

class ScalaImpl extends JavaImpl

Output

class ScalaImpl needs to be abstract, since def compareTo(x$0: T): Int in trait Comparable in package java.lang is not defined 
(Note that
 parameter T in def compareTo(x$0: T): Int in trait Comparable in package java.lang does not match
 parameter java.lang.ref.Reference[?] in def compareTo(ref: java.lang.ref.Reference[?]): Int in class JavaImpl
 )
class ScalaImpl extends JavaImpl

Expectation

Should just compile. Note that new JavaImpl works in scala... here the compiler doesn't complain.

I understand that the scala compiler has a point with its error, but is ultimately wrong in this case and completely prevents me from overriding this class. As far as I can see there is nothing I can do (neither in scala nor in java (except from changing the method)) to implement JavaImpl in any way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions