Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala Class[_$1] where type _$1

Right now trying to instantiate a new JSONConverter to register Jackson's Scala module.

  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] { }.

The problem with the above code is that Scala seems to be having a difficult time with 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!

Update

Although @wingedsubmariner had an answer that allowed this to originally compile, as soon as I went to write more code the issue cascaded further. 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:

[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. Any ideas here?

like image 723
crockpotveggies Avatar asked Nov 20 '25 03:11

crockpotveggies


1 Answers

runtimeClass is retuning a Class with the wrong type parameter. Try:

new JSONConverter(classTag[T].runtimeClass.asInstanceOf[Class[T]], bucketName(clientId))
like image 94
wingedsubmariner Avatar answered Nov 22 '25 18:11

wingedsubmariner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!