1
我很驚訝地發現,鏈接調用枚舉的作品。我恰好有一個名爲'name'的枚舉實例,當我忘記括號時,它被引用而不是名稱()。應該枚舉允許鏈接調用? 使用Groovy 2.4.10 - 見下面的最後3個電話:Groovy枚舉 - 調用鏈
Groovy Shell (2.4.10, JVM: 1.8.0_121)
Type ':help' or ':h' for help.
groovy:000> public enum Compass { north, south }
===> true
groovy:000> Compass.north
===> north
groovy:000> Compass.north.name
ERROR groovy.lang.MissingPropertyException:
No such property: name for class: Compass
groovy:000> Compass.north.name()
===> north
groovy:000> public enum Compass { north, south, name }
===> true
groovy:000> Compass.north.name()
===> north
groovy:000> Compass.north.name
===> name
groovy:000> Compass.north.south
===> south
groovy:000> Compass.north.south.north
===> north
FWIW,Java表現出相同的行爲。 –