-
Notifications
You must be signed in to change notification settings - Fork 21
Scala -> Java compatibility. Compiler can't choose most specific overloaded method #4775
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
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4775?orig=1 |
@paulp said: class A {
def f[T](x: T): T = x
def f[T](x: T, xs: T*): T = x
f(5)
// but this works:
def g(x: Int): Int = x
def g(x: Int, xs: Int*): Int = x
g(5)
} |
@paulp said:
|
@paulp said: foo[Element](new Element, classOf[Element], false) However in this particular case, the fact that classOf returns Class[T] but getClass returns Class[_ <: T] means it still appears ambiguous. Here are two ways you can actually call it. foo[Element](new Element, (new Element).getClass, false) |
@paulp said: |
@adriaanm said: |
Espen Wiborg (espenhw) said: Interestingly, you can explicitly call the varargs f with f(5, Seq.empty: _*) but there is no way to specify the non-varargs method (at least I can't come up with one). I've tried to wrap my head around the language in the relevant bit of the JLS (section 15.12.2.5); |
daveclay said: when(serviceReference.getProperty("name")).thenReturn(name) Results in the compilation error: scala: ambiguous reference to overloaded definition,
both method thenReturn in trait OngoingStubbing of type (x$1: Object, x$2: <repeated...>[Object])org.mockito.stubbing.OngoingStubbing[Object]
and method thenReturn in trait OngoingStubbing of type (x$1: Object)org.mockito.stubbing.OngoingStubbing[Object]
match argument types (String)
when(serviceReference.getProperty("name")).thenReturn(name)
^ And to fix this, I have to be explicit in typing the instance of OngoingStubbing: when(serviceReference.getProperty("name")).asInstanceOf[OngoingStubbing[String]].thenReturn(name) Which can get pretty ridiculous, depending on the thing I'm stubbing: when(bundleContext.getService(serviceReference)).asInstanceOf[OngoingStubbing[LoginHandler[AuthData, User, String]]].thenReturn(handler) It's not Friday yet, but I guess it is time to get beer and/or pray. |
matan said: |
Uh oh!
There was an error while loading. Please reload this page.
Java example:
Scala example:
Obviously two methods are applicable, but one of them is definetely more specific (which is without varargs).
The text was updated successfully, but these errors were encountered: