2016-11-28 27 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擴展模型。