[英]Inferred type arguments [_$1] do not conform to method type parameter bounds
I have a case class:我有一个案例 class:
case class AnomalyCheckConfigBuilder[S <: State[S]](anomalyDetectionStrategy: AnomalyDetectionStrategy,
analyzer: Analyzer[S, Metric[Double]],
anomalyCheckConfig: Option[AnomalyCheckConfig] = None)
And i have a function which returns a collection of the above case class objects in the form of a Seq.我有一个 function,它以 Seq 的形式返回上述案例 class 对象的集合。
val anomalyCheckConfig : Seq[AnomalyCheckConfigBuilder[_]] = jobConfig.validate.get.getAnomalyCheckConfigBuilder
I am adding the objects from the above list to another method who's signature is below:我将上面列表中的对象添加到签名如下的另一个方法:
def addAnomalyCheck[S <: State[S]](
anomalyDetectionStrategy: AnomalyDetectionStrategy,
analyzer: Analyzer[S, Metric[Double]],
anomalyCheckConfig: Option[AnomalyCheckConfig] = None)
: this.type
I am doing the below operation:我正在做以下操作:
anomalyCheckConfig.foreach(x=>{
verificationSuite = verificationSuite.addAnomalyCheck(x.anomalyDetectionStrategy,x.analyzer,x.anomalyCheckConfig)
})
Where verificationSuite is a opensource code from Deeque其中 verificationSuite 是来自Deeque的开源代码
Error i am getting on the above code is:我在上面的代码中遇到的错误是:
error: inferred type arguments [_$1] do not conform to method addAnomalyCheck's type parameter bounds [S <: com.amazon.deequ.analyzers.State[S]]
[ERROR] verificationSuite = verificationSuite.addAnomalyCheck(x.anomalyDetectionStrategy,x.analyzer,x.anomalyCheckConfig)
error: type mismatch;
[ERROR] found : com.amazon.deequ.analyzers.Analyzer[_$1,com.amazon.deequ.metrics.Metric[Double]]
[ERROR] required: com.amazon.deequ.analyzers.Analyzer[S,com.amazon.deequ.metrics.Metric[Double]]
[ERROR] verificationSuite = verificationSuite.addAnomalyCheck(x.anomalyDetectionStrategy,x.analyzer,x.anomalyCheckConfig)
The code fails on compile time and scala is unable to understand the state, and i am unable to understand where is _$1
coming from.代码在编译时失败,scala 无法理解 state,我无法理解_$1
来自哪里。 Would appreciate some inputs on thiss希望对此有一些意见
This clearly says that Scala needs you to provide an instance of 'S'
which is a subtype of State
class.这清楚地表明 Scala 需要您提供'S'
的实例,它是State
class 的子类型。
What you need to do is:你需要做的是:
anomalyCheckConfig.foreach(x=>{
verificationSuite = verificationSuite.addAnomalyCheck[S](x.anomalyDetectionStrategy, x.analyzer.asInstanceOf[Analyzer[S, Metric[Double]]], x.anomalyCheckConfig)
})
Also you need to wrap this under a function which accepts S
as a subtype of State
您还需要将其包装在 function 下,它接受S
作为State
的子类型
def anmomaly[S <: State[S]](){
anomalyCheckConfig.foreach(x=>{
verificationSuite = verificationSuite.addAnomalyCheck[S](x.anomalyDetectionStrategy, x.analyzer.asInstanceOf[Analyzer[S, Metric[Double]]], x.anomalyCheckConfig)
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.