- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
MockIto and Generics => Compile error.
Mon, 2012-02-06, 15:53
Dear all,I am striving to make the following code compile
when[java.util.Iterator[OisImpl]](collection.iterator).thenReturn(oisCollection.iterator)
but I obtain:
error: overloaded method value thenReturn with alternatives:(java.util.Iterator[OisImpl],<repeated...>[java.util.Iterator[OisImpl]])org.mockito.stubbing.OngoingStubbing[java.util.Iterator[OisImpl]] <and> (java.util.Iterator[OisImpl])org.mockito.stubbing.OngoingStubbing[java.util.Iterator[OisImpl]]cannot be applied to (t: Iterator[OisImpl])when[java.util.Iterator[OisImpl]](collection.iterator).thenReturn(t=oisCollection.iterator)
I have tried also without specifiying the type and let the inferer find it, but I got the same error :(
Do you have any suggestions?
Best RegardsEdmondo
when[java.util.Iterator[OisImpl]](collection.iterator).thenReturn(oisCollection.iterator)
but I obtain:
error: overloaded method value thenReturn with alternatives:(java.util.Iterator[OisImpl],<repeated...>[java.util.Iterator[OisImpl]])org.mockito.stubbing.OngoingStubbing[java.util.Iterator[OisImpl]] <and> (java.util.Iterator[OisImpl])org.mockito.stubbing.OngoingStubbing[java.util.Iterator[OisImpl]]cannot be applied to (t: Iterator[OisImpl])when[java.util.Iterator[OisImpl]](collection.iterator).thenReturn(t=oisCollection.iterator)
I have tried also without specifiying the type and let the inferer find it, but I got the same error :(
Do you have any suggestions?
Best RegardsEdmondo
I ran into this problem when trying to use Mockito recently. It seems there's an issue with interop between java and scala here. The method thenReturn is overloaded by either taking a single param or a varargs. Java can handle this but Scala cannot.
See this ticket for a more detailed explanation: https://issues.scala-lang.org/browse/SI-2991
-a
On Mon, Feb 6, 2012 at 6:53 AM, Edmondo Porcu <edmondo.porcu@gmail.com> wrote: