0
我发现了Groovy 2.4.7,1.6.0 JVM在尝试评估而不是 instanceof条件时没有预料到的行为。Groovy“not instanceof”特性
在总结:
class Foo {
static Boolean bar() {
String x = "Personally, I don't really like King Crimson"
return (!x instanceof Integer)
}
}
我预计Foo.bar()将因为x是不整数的一个实例,但是Foo.bar()返回false返回true。相比之下以下返回true:
class Foo {
static Boolean bar() {
String x = "Personally, I don't really like King Crimson"
return !(x instanceof Integer)
}
}
问题是学术的,但出于好奇:这是一个错误的语言或有我误解了应该如何instanceof来工作?作为字符串包含一些文本
(!x) instanceof Integer
所以它是将字符串转换为布尔(!'Hello'
是false
:
感谢,向好知道。 –