Reputation: 1358
import org.apache.spark.api.java.JavaRDD
import org.apache.spark.rdd.RDD
import scala.reflect.ClassTag
class TestRDD[T: ClassTag](rdd: RDD[T]) extends JavaRDD(rdd)
This statement is accepted from the console. However at compile time the following error is thrown:
No ClassTag available for T
[error] class TestRDD[T: ClassTag](rdd: RDD[T]) extends JavaRDD(rdd)
[error] ^
[error] one error found
[error] (jobs/it:compileIncremental) Compilation failed
Upvotes: 8
Views: 6466
Reputation: 1358
Well this is the embarassing solution:
class TestRDD[T: ClassTag](rdd: RDD[T]) extends RDD[T](rdd: RDD[T])
Upvotes: 2
Reputation: 14217
I think you want this:
class TestRDD[T](rdd: List[T])(implicit c: ClassTag[T]) extends JavaRDD(rdd)
use implicit
to auto implicit the ClassTag
of generic T.
Upvotes: 12
Reputation: 5275
Due to jvm template type erase, the compiler can't get type information of T
from rdd
.
But type information of T
is stored in class RDD
, maybe you can get the classtag of T
from RDD
class
Upvotes: 0