如何防止在对象数组中获取 Groovy 布尔值?
我正在尝试创建一个对象数组(Object[])以传递给方法(IDescriptor):
Object[] newValues = {
Boolean.TRUE
}
descriptor.setParameters(newValues)
特定的描述符期望数组中的第一个值是 java.lang.Boolean 对象。然而,Groovy 似乎正在转换为它自己的布尔类,当我运行代码时(上面不是完整的代码),描述符报告数组中的第一个对象不是 java.lang.Boolean 对象。
并不是说它的信息量很大,这是堆栈跟踪:
org.openscience.cdk.exception.CDKException: The first parameter must be of type Boolean
at org.openscience.cdk.qsar.descriptors.molecular.AromaticAtomsCountDescriptor.setParameters(AromaticAtomsCountDescriptor.java:118)
当我添加断言(在错误中重复)时,我收到此错误:
assert newValues[0] instanceof java.lang.Boolean
| | |
| | false
| AromaticAtomCountDescriptorParams$_run_closure3@1cc5069
[AromaticAtomCountDescriptorParams$_run_closure3@1cc5069]
How can I make certain Groovy using the Java Boolean class in the array,而不是它自己的更丰富的类?
I am trying to create an Object array (Object[]) to be passed to a method (IDescriptor):
Object[] newValues = {
Boolean.TRUE
}
descriptor.setParameters(newValues)
The particular descriptor expects the first value in the array to be a java.lang.Boolean object. However, it seems Groovy is converting to its own boolean class, and when I run the code (the above is not the full code), the descriptor reports that the first Object in the array is not a java.lang.Boolean object.
Not that it is very informative, this is the stacktrace:
org.openscience.cdk.exception.CDKException: The first parameter must be of type Boolean
at org.openscience.cdk.qsar.descriptors.molecular.AromaticAtomsCountDescriptor.setParameters(AromaticAtomsCountDescriptor.java:118)
When I add an assert (repeated in the error), I get this error:
assert newValues[0] instanceof java.lang.Boolean
| | |
| | false
| AromaticAtomCountDescriptorParams$_run_closure3@1cc5069
[AromaticAtomCountDescriptorParams$_run_closure3@1cc5069]
How can I make sure Groovy uses the Java Boolean class in the array, instead of its own richer class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用正确的大括号:
您使用了
{}
,它创建了一个闭包。这也是可行的,因为闭包有很多特殊的能力,但它们不是列表,而是数组。因此,Groovy 将右侧的单个元素包装在列表中,然后分配数组newValues
。Use the correct braces:
You used
{}
which creates a closure. That also works because closures have a lot of special abilities but they aren't lists are arrays. So Groovy wraps the single element on the right hand side in a list and then assigns the arraynewValues
.