Intellij idea Spock:尝试比较两个BigDecimal数组时出现警告

Intellij idea Spock:尝试比较两个BigDecimal数组时出现警告,intellij-idea,groovy,spock,Intellij Idea,Groovy,Spock,我正在测试我的程序。特别是,我需要比较两个BigDecimal数组: def "compare two BigDecimal arrays"(){ given: BigDecimal[] c = [2, 3] expect: c == [2,3] as BigDecimal[] } IntelliJ IDEA报告了一个警告: 'equals' in 'org.codehaus.groovy.runtime.DefaultGroovyMethods' cannot be appl

我正在测试我的程序。特别是,我需要比较两个
BigDecimal
数组:

def "compare two BigDecimal arrays"(){
  given:
  BigDecimal[] c = [2, 3]
  expect:
  c == [2,3] as BigDecimal[]
}
IntelliJ IDEA报告了一个警告:

'equals' in 'org.codehaus.groovy.runtime.DefaultGroovyMethods' cannot be applied to '(java.math.BigDecimal[])' less... (Ctrl+F1) 
此检查报告具有不兼容类型的分配

在DefaultGroovyMethods中,我发现了以下方法:

static boolean equals(java.lang.Object[] left, java.util.List right)
那么,我想,可以这样做:

def "compore BigDecimal[] and List<BigDecimal>"(){
  given:
  BigDecimal[] c = [2, 3]
  expect:
  c == [2,3]
}
def“compore BigDecimal[]和List”(){
鉴于:
BigDecimal[]c=[2,3]
期望:
c==[2,3]
}
但现在出现了以下警告:

'==' between objects of inconvertible types 'BigDecimal[]' and 'List<Integer>' less... (Ctrl+F1) 

Reports calls to .equals() and == operator usages where the target and argument are of incompatible types. While such a call might theoretically be useful, most likely it represents a bug
“==”在不可转换类型“BigDecimal[]”和“List”less的对象之间。。。(Ctrl+F1)
报告对.equals()和==运算符的调用,其中目标和参数的类型不兼容。虽然这样一个调用在理论上可能有用,但它很可能代表一个bug
因此,我的问题是:进行
BigDecimal[]
比较的正确方法是什么,这样就不会报告任何警告


备注:即使报告了警告,两个测试运行都没有任何问题

我想出现这个问题是因为IDE看到了两个不同的问题。首先,当使用
.equals()
方法或
=
运算符比较两个不兼容的类型时,它引用Java
.equals()
方法。以下情况就是这种情况:

c == [2, 3] // BigDecimal[] == List<Integer>
2)或者您可以通过将
@SuppressWarnings(“grequalBetweenInConvertibleTypes”)
添加到您的方法(或测试类,如果您有其他方法也生成相同的警告),来抑制此警告:

@SuppressWarnings(“GrEqualsBetweenInconvertibleTypes”)
定义“比较BigDecimal[]和列表(2)”(){
鉴于:
BigDecimal[]c=[2,3]
期望:
c==[2,3]
}
第二个选项允许您在没有IDE警告的情况下使用
c==[2,3]
比较,我猜这是您所期望的

def "compare BigDecimal[] and List<BigDecimal> (1)"(){
    given:
    BigDecimal[] c = [2, 3]

    expect:
    DefaultGroovyMethods.equals(c, [2,3])
}
@SuppressWarnings("GrEqualsBetweenInconvertibleTypes")
def "compare BigDecimal[] and List<BigDecimal> (2)"(){
    given:
    BigDecimal[] c = [2, 3]

    expect:
    c == [2,3]
}