I am working with java lib in scala.
I need to implement an abstract class in scala, but there is a problem with guava TypeToken, which is used in an abstract class in java. The problem is that sometimes in scala TypeToken cannot infer a generic type:
import com.google.common.reflect.TypeToken class SomeClass[T] { val tok = new TypeToken[T](getClass){} } object TypeTokenTest extends App { val ok = new SomeClass[String]{} println(ok.tok) // `java.lang.String`, OK!! def wrap[O]() = { new SomeClass[O]{} } val notOk = wrap[String]() println(notOk.tok) // `O`, not Ok ... }
So, in the above code, if this is a simple use, it works very well. But if there is indirection (a specific type is passed from the function to the class), it no longer works.
Any suggestions on how to make it work?
darkjh source share