Почему groovy.class возвращает значение, отличное от.getClass()

Согласноhttp://groovy.codehaus.org/Things+you+can+do+but+better+leave+undone

  1. Accessing an object's type like a property

Using.class instead of.getClass() is ok - as long as you know exactly what kind of object you have. But then you don't need that at all. Otherwise, you run in the risk of getting null or something else, but not the class of the object.

a = [:] println a.class.simpleName // NullPointerException, because a.class is null.

Может кто-нибудь объяснить, почему это так? Почему .classвозвращает что-то отличное отgetClass()

15
задан Jeff Storey 16 July 2012 в 21:39
поделиться