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表现出相同的行为。 –