Resolution Groovy Map Class

Anyone can explain why calling the class [:]. on the map returns null when calling [:]. getClass () returns the expected result. Example below

one -

["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

+7
grails groovy
source share
1 answer

Here is the answer

http://jira.codehaus.org/browse/GROOVY-1824

EDIT - required. I think the semantics of the Map is that if you have

 def m = [one:1, two:2] 

you must have access to the records on the map, for example

 m.one 

In other words, accessing a map is like getting a property on a map object. If a

 m.class 

returned the class, it would break the semantics, because the "class" is not a key added to the map by the programmer.

Here is what I collect ....

+11
source share

All Articles