As we all know, we can initialize a object of template parameter T in C++.
template <typename T>
struct Cont{
T t;
}
I want to do the same in scala, so I write the following codes. There are some other classes which extends Evaluator, and EvaluateComponent is something like a wrapper. I can write code like new EvaluateComponent[BinaryClassificationEvaluator].evaluate(df)
abstract class Evaluator extends Serializable{
var predCol = "prediction"
var trueCol = "label"
def evaluate(dataset: DataFrame) : String
def evaluateRDD(dataset: RDD[(Double, Double)]) : String
}
class EvaluateComponent[E <: Evaluator : ClassTag] {
val evaluator = new E
}
class BinaryClassificationEvaluator extends Evaluator {
...
}
However it doesn't compile with error class type required but E found.
The post does not solve my question because I want evaluator to be initialized.
Eor a way to construct it. You can not magically create an instance of any arbitrary class.