Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolving Groovy Map class

Tags:

grails

groovy

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

like image 666
ken Avatar asked Nov 06 '10 14:11

ken


1 Answers

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....

like image 163
hvgotcodes Avatar answered Nov 10 '22 16:11

hvgotcodes