scala - How to get ClassTag for specialized types? -


scala> val = (0, 0) i: (int, int) = (0,0)  scala> i.getclass res0: class[_ <: (int, int)] = class scala.tuple2$mcii$sp  scala> def f[t: reflect.classtag](t: t) = implicitly[reflect.classtag[t]] f: [t](t: t)(implicit evidence$1: scala.reflect.classtag[t])scala.reflect.classtag[t]      scala> f(i) res1: scala.reflect.classtag[(int, int)] = scala.tuple2 

the implicit classtag argument wrong. scala.tuple2 not class of i. correct classtag scala.tuple2$mcii$sp.

this behavior problem us, use kryo serialization. give class argument readobject. take classtag, give wrong class specialized classes. read garbage.

am using classtag wrong? or bug in scala 2.11.0?

the correct answer not scala.tuple2$mcii$sp. asking nominal (and erased!) type of tuple2[int, int] @ compile time, tuple2. note getclass different thing, gets class of runtime value.


Comments

Popular posts from this blog

rdbms - what exactly the undo information lives in oracle? -

bash - How do you programmatically add a bats test? -

java - Getting exception in JDBC thin driver -