Skip to content

Java interop: NoSuchMethodError for Java method returning T <: Object & Comparable #9441

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

Closed
sjrd opened this issue Jul 27, 2020 · 1 comment

Comments

@sjrd
Copy link
Member

sjrd commented Jul 27, 2020

Minimized code

object Test {
  def main(args: Array[String]): Unit = {
    val list = new java.util.ArrayList[String]()
    println(java.util.Collections.min(list))
  }
}

Output

Exception in thread "main" java.lang.NoSuchMethodError: java.util.Collections.min(Ljava/util/Collection;)Ljava/lang/Comparable;
        at Test$.main(hello.scala:4)
        at Test.main(hello.scala)

Expectation

I expect this to run correctly.

Notes

JavaDoc of java.util.Collections.min

public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll)

For Java (and Scala 2), the erasure of that method is

min(Collection)Object

but Dotty thinks its erasure is

min(Collection)Comparable

hence the NoSuchMethodError.

This issue prevents the Scala.js test CollectionsOnCollectionsTest.testMinMax1 from linking, at the following 2 lines:
https://github.com/scala-js/scala-js/blob/6b9f04b0c0531d889235726d8956cb01a4c7476d/test-suite/shared/src/test/scala/org/scalajs/testsuite/javalib/util/CollectionsOnCollectionsTest.scala#L36-L37

Possibly related to #9175

@smarter
Copy link
Member

smarter commented Jul 30, 2020

Duplicate of #7963

@smarter smarter marked this as a duplicate of #7963 Jul 30, 2020
@smarter smarter closed this as completed Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants