5

I am reading the Groovy in Action (GINA) book. In chapter 9, there is this listing:

class MyClass {
    def first = 1
    def getSecond() { first * 2 }
    public third = 3

}

obj = new MyClass()

keys = ['first', 'second', 'third', 'class', 'metaClass']
assert obj.properties.keySet() == new HashSet( keys )  // fail

However, the following assert is actually the right one:

keys = ['first', 'second', 'class']
assert obj.properties.keySet() == new HashSet( keys )

So, what has changed about groovy class properties after the GINA book? Thank you.

4

1 回答 1

2

从这本书的论坛上看,那一点似乎是一个错误,或者发生了一些变化,没有人确定是什么。

您最好访问本书的MEAP 第二版,因为这涵盖了 groovy 2

于 2013-08-20T06:07:46.050 回答