2016-11-28 29 views
3

我正在实现一个自定义的估计器,它遇到了访问参数ava.util.NoSuchElementException: Failed to find a default value for isInList的麻烦。它的定义如下:自定义估算器为什么最终会覆盖Nothing类型?

trait PreprocessingParams extends Params { 
    final val isInList = new Param[Array[String]](this, "isInList", "list of isInList items") 
} 

为了更好地调试的问题,我创建了一个小例子,这里https://gist.github.com/geoHeil/8dc7a6b6938a517f068e7fd6a981ed12ExampleTrans作品就好了。但是,我宁愿将变压器的功能包括在执行一些数据清理的估算器中。

但现在我面对奇怪的编译问题overriding method has wrong type - expecting Nothing

什么是错的返回类型我ExampleEstimator的?

回答

3

您没有指定Estimator类型构造函数的通用类型,因此使用Nothing代替。

用途:

class ExampleEstimator(override val uid: String) 
    extends Estimator[ExampleTransModel] with PreprocessingParams { 
    ... 
} 

Estimator完整定义如下:

abstract class Estimator[M <: Model[M]] extends PipelineStage 

注意泛型类型M扩展模型。