[英]Scala Class[_$1] where type _$1
Right now trying to instantiate a new JSONConverter
to register Jackson's Scala module. 现在,尝试实例化一个新的JSONConverter
来注册Jackson的Scala模块。
private def getConverter(implicit m: ClassTag[T]) = {
new JSONConverter[T](classTag[T].runtimeClass, bucketName)
JSONConverter.registerJacksonModule(DefaultScalaModule)
converter
}
The above code sits in a standard Scala trait that looks like trait Writeable[T] { }
. 上面的代码位于标准的Scala特征中,该特征看起来像trait Writeable[T] { }
。
The problem with the above code is that Scala seems to be having a difficult time with Types. 上面的代码的问题在于Scala似乎很难使用Types。 Compiler error is: 编译器错误是:
[error] found : Class[_$1] where type _$1
[error] required: Class[T]
[error] val converter = new JSONConverter[T](classTag[T].runtimeClass, bucketName(clientId))
[error] ^
[error] one error found
Anyone know the source or easy fix of this issue? 有人知道此问题的来源或简单的解决方法吗? Thanks! 谢谢!
Although @wingedsubmariner
had an answer that allowed this to originally compile, as soon as I went to write more code the issue cascaded further. 尽管@wingedsubmariner
的答案允许它最初进行编译,但是当我去编写更多代码时,问题就更加@wingedsubmariner
了。 I'll show an example: 我将举一个例子:
val o = bucketLookup(clientId).fetch(id, classTag[T].runtimeClass).withConverter(converter).withRetrier(DB.retrier).r(DB.N_READ).execute()
At withConverter
the compiler throws the same error: 在withConverter
,编译器将引发相同的错误:
[error] found : com.basho.riak.client.convert.JSONConverter[T]
[error] required: com.basho.riak.client.convert.Converter[_$1] where type _$1
[error] val o = bucketLookup(clientId).fetch(id, classTag[T].runtimeClass).withConverter(converter).withRetrier(DB.retrier).r(DB.N_READ).execute()
I even tried doing the same type casting using converter.asInstanceOf[JSONConverter[T]]
but inheritance ( JSONConverter<T> extends Converter<T>
) seems to cascade the issue. 我什至尝试使用converter.asInstanceOf[JSONConverter[T]]
进行相同类型的converter.asInstanceOf[JSONConverter[T]]
但是继承( JSONConverter<T> extends Converter<T>
)似乎可以解决此问题。 Any ideas here? 这里有什么想法吗?
runtimeClass
is retuning a Class
with the wrong type parameter. runtimeClass
正在使用错误的type参数重新调整Class
。 Try: 尝试:
new JSONConverter(classTag[T].runtimeClass.asInstanceOf[Class[T]], bucketName(clientId))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.