When I was using Groovy to compare two Strings like below, I got a “false” result which was expected to be “true”:
1 2 3
It took me some time to realize that the problem is: the “foo” variable is not a String instance, but a GStringImpl instance instead. So the official Groovy code here should be:
1 2 3
Problem resolved? No! The real problem here is: this is unintuitive, “GStringImpl” is not “String”! But why?
… That’s crazy because Java is an object-oriented language and the way you interoperate and work in an object-oriented language is you sub-class things, but the fundamental types, like string, you are not allowed to sub-class, they made it final. I don’t know why. …
This fact also reminds me that, even a dynamic type language based on JVM cool as Groovy, the things it get from JVM are not all cool. And pathetically, the Groovy language can do nothing with it.