Scala 2.8 可以正确处理 Boolean 和 java.lang.Boolean 吗?
请考虑以下情况:
scala> val a:java.lang.Boolean = true
a: java.lang.Boolean = true
scala> val b = true
b: Boolean = true
scala> a == b
res4: Boolean = true
scala> b == a
<console>:8: warning: comparing values of types Boolean
and java.lang.Boolean using `==' will always yield false
b == a
^
res5: Boolean = true
警告说它将产生 false
,但它会产生 true
。
斯卡拉2.8。
Consider the following:
scala> val a:java.lang.Boolean = true
a: java.lang.Boolean = true
scala> val b = true
b: Boolean = true
scala> a == b
res4: Boolean = true
scala> b == a
<console>:8: warning: comparing values of types Boolean
and java.lang.Boolean using `==' will always yield false
b == a
^
res5: Boolean = true
The warning says that it will yield false
but it yields true
.
Scala 2.8.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一些源代码控制考古表明,2.8.1 之后这些警告的处理得到了改进。以下是对这些警告的单元测试的带注释的修订。
https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/test/files/neg/checksensible.scala?annotate=blame&rev=25638
这是比较的到 2.8.1 Final 中的 rev 19169 更加基本:
https://lampsvn.epfl.ch /trac/scala/browser/scala/tags/R_2_8_1_final/test/files/neg/checksensible.scala
我认为这有道理2.8.1 之后对此给予了更多关注。
查看一些错误报告,似乎警告确实如此 - 希望有助于识别错误。如果您知道自己在做什么(例如比较 java Boolean 和 scala Boolean),那么您可以忽略。
A bit of source code control archaeology shows that handling of those warnings were improved after 2.8.1. Here is the annotated revisions to the unit tests for those warnings.
https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/test/files/neg/checksensible.scala?annotate=blame&rev=25638
This is compared to rev 19169 in 2.8.1 final that is a lot more basic:
https://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_8_1_final/test/files/neg/checksensible.scala
I think this gives a sense that more attention was provided to this after 2.8.1.
Looking at some bug reports, it seems the warning are really just that - hopefully helping identify errors. If you know what you're doing (such as comparing java Boolean and scala Boolean), then you can ignore.
有趣的是,这种情况已经倒退了。在最近的警告增强中,我必须排除数字和缺少布尔值。 trunk 中用于比较 java.lang.Boolean 和 Boolean 的错误消息令人印象深刻地令人困惑。
Interestingly, this has regressed. In recent warning enhancements I must be excluding numerics and missing boolean. The error message in trunk for comparing java.lang.Boolean and Boolean is impressively confusing.