1

I am using a library which is written by amazon in scala here

The trait goes like this :

trait Analyzer[S <: State[_], +M <: Metric[_]]

I am trying to make a case object to store some information and an instace of the above Analyzer is a part of it.

case class AnomalyCheckConfigBuilder(anomalyDetectionStrategy: AnomalyDetectionStrategy,
                                     analyzer: Analyzer[_, Metric[_]],
                                     anomalyCheckConfig: Option[AnomalyCheckConfig] = None)

I'm getting the below error :

error: type arguments [_$1,com.amazon.deequ.metrics.Metric[_]] do not conform to trait Analyzer's type parameter bounds [S <: com.amazon.deequ.analyzers.State[_],+M <: com.amazon.deequ.metrics.Metric[_]]
       case class AnomalyCheckConfigBuilder(anomalyDetectionStrategy: AnomalyDetectionStrategy,

Not sure, what's the problem here. Does anyone understand this?

Shiv
  • 105
  • 7

1 Answers1

2

The thing is, if you look at the definition of State trait, you will see trait State[S <: State[S]] which means the type inside the State type argument (named S), MUST be a subtype of State of that type, for instance: trait MyState extends State[MyState]. but using underscore in analyzer: Analyzer[_(this one), Metric[_]] does not assure the compiler that this type extends State of that type. to make the compile error go away, you can do:

case class AnomalyCheckConfigBuilder(anomalyDetectionStrategy: AnomalyDetectionStrategy,
                                     analyzer: Analyzer[_ <: State[_], Metric[_]],
                                     anomalyCheckConfig: Option[AnomalyCheckConfig] = None)

which is shorter form of

case class AnomalyCheckConfigBuilder[StateType <: State[_]](anomalyDetectionStrategy: AnomalyDetectionStrategy,
                                     analyzer: Analyzer[StateType, Metric[_]],
                                     anomalyCheckConfig: Option[AnomalyCheckConfig] = None)
AminMal
  • 3,070
  • 2
  • 6
  • 15
  • Since you helped on this, can you help on this. https://stackoverflow.com/questions/71297290/inferred-type-arguments-1-do-not-conform-to-method-type-parameter-bounds – Shiv Feb 28 '22 at 16:51