Reputation: 22171
I want to call this Java method (part of an API), from Scala (2.10.3):
public <R> ConvertedResult<R> to(Class<R> type,
ResultConverter<Map<String, Object>, R> converter)
ResultConverter
interface being:
public interface ResultConverter<T, R> {
R convert(T value, Class<R> type);
}
First, I created my converter (in Scala so):
class MyVOConverter extends ResultConverter[Map[String, AnyRef], MyVO] {
def convert(queryResult: Map[String, AnyRef],
`type`: Class[MyVO]): MyVO = {
//...
}
}
providing a type and my MyVOConverter
like this, when the call is made:
myResult.to(classOf[MyVO], new MyVOConverter())
However, Scala compiler warns about this:
Type mismatch, expected: ResultConverter[Map[String, AnyRef], NotInferedR],
actual: MyVOConverter
How to deal with this case?
Upvotes: 0
Views: 506
Reputation: 297195
The Map
on the interface is java.util.Map
, but, assuming you haven't imported that, you are using scala.collection.immutable.Map
and, therefore, incompatible.
Upvotes: 1