Anyone can explain why calling [:].class on a map return null while calling [:].getClass() return the expected result Map. See example below
1-
["test",[test:"test"],23].each {
println it.class
}
class java.lang.String
null
class java.lang.Integer
2-
["test",[test:"test"],23].each {
println it.getClass()
}
class java.lang.String
class java.util.LinkedHashMap
class java.lang.Integer
Ken
Here is the answer
https://issues.apache.org/jira/browse/GROOVY-1824
EDIT -- sure. I think the semantics of a Map are such that if you have
def m = [one:1, two:2]
you are supposed to be able to access the entries in the map like
m.one
in other words, access into the map is like getting a property on the map object. If
m.class
returned the class, it would break those semantics, because 'class' is not a key added to the map by the programmer.
Thats what I gather....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With