Why does groovy .class return a different value than .getClass()

后端 未结 2 1646
悲&欢浪女
悲&欢浪女 2020-12-17 14:31

According to http://groovy.codehaus.org/Things+you+can+do+but+better+leave+undone

  1. Accessing an object\'s type like a property
2条回答
  •  Happy的楠姐
    2020-12-17 14:55

    Because when a is a map, a.class is the same in Groovy as a.get( "class" ). As you can see in the example in the docs, this will return null. That's why the rule trends to be to use getClass unless you're absolutely sure the variable won't be a map

提交回复
热议问题