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?
接口上的Map
是java.util.Map
,但是,假设您尚未导入,则使用的是scala.collection.immutable.Map
,因此不兼容。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.