Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No ClassTag available for T

Tags:

scala

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
like image 334
autodidacticon Avatar asked Jan 21 '16 05:01

autodidacticon


1 Answers

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.

like image 175
chengpohi Avatar answered Oct 22 '22 03:10

chengpohi