简体   繁体   English

推断类型 arguments [_$1] 不符合方法类型参数边界

[英]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.

相关问题 推断的类型参数[Boolean]不符合方法过滤器的类型参数范围[T &lt;:slick.lifted.Rep [_]] - inferred type arguments [Boolean] do not conform to method filter's type parameter bounds [T <: slick.lifted.Rep[_]] 理解Scala中的“推断类型参数不符合类型参数边界”错误 - Understanding “inferred type arguments do not conform to type parameter bounds” errors in Scala Scala:类型参数不符合类类型参数范围 - Scala: type arguments do not conform to class type parameter bounds 类型参数不符合特征栏的类型参数范围 - type arguments do not conform to trait Bar's type parameter bounds 类型参数不符合特征Subtractable的类型参数边界 - type arguments do not conform to trait Subtractable's type parameter bounds 理解Scala中的“类型参数不符合类型参数边界”错误 - Understanding “type arguments do not conform to type parameter bounds” errors in Scala Scala错误:类型参数不符合类类型参数范围 - Scala error: type arguments do not conform to class type parameter bounds 类型参数[W]不符合特征类型参数范围 - type arguments [W] do not conform to trait type parameter bounds Scala 类型 arguments 不符合类型参数界限 - Scala type arguments do not conform to type parameter bounds 类型 arguments 不符合特征类型参数界限 - Type arguments do not conform to trait type parameter bounds
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM