[英]Avoid compiler warning using wildcard for primitive types in Spock
I'm using Spock Framework for testing my Java application.我正在使用 Spock 框架来测试我的 Java 应用程序。 The compiler warns me whenever I try to instrument a Mock
using a wildcard for a primitive type.每当我尝试使用原始类型的通配符来检测Mock
时,编译器都会警告我。
For example (trivial example):例如(简单的例子):
service.add(_, _) >> 42
Both the above parameters are primitive int
.上述两个参数都是原始int
。 The compiler gives me the following warning:编译器给了我以下警告:
Warning:(34, 30) 'add' in 'Service' cannot be applied to '(java.lang.Object, java.lang.Object)'警告:(34, 30) 'Service' 中的 'add' 不能应用于 '(java.lang.Object, java.lang.Object)'
At runtime, the test passed without any problem.在运行时,测试通过,没有任何问题。 However, if I try to specify the type of wildcards, the test fails.但是,如果我尝试指定通配符的类型,则测试失败。
How can I avoid the above warning message?如何避免上述警告信息?
You should use type wrappers instead of primitives.您应该使用类型包装器而不是原语。
See the project at github.com/jeffbrown/riccardocardin .请参阅github.com/jeffbrown/riccardocardin上的项目。
lib/src/test/groovy/riccardocardin/LibraryTest.groovy#L9 works. lib/src/test/groovy/riccardocardin/LibraryTest.groovy#L9有效。
1 * add(_ as Integer, _ as Integer) >> 2112
github.com/spockframework/spock/issues/669 explains why this is not a bug. github.com/spockframework/spock/issues/669解释了为什么这不是一个错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.