Iterate enumerated class instances

后端 未结 2 832
一向
一向 2021-01-21 01:23

Is there a simple way to iterate over all enumerated instances of a class in Ceylon?

Just like values() for Java enums?

abstract class Suit(         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-21 01:43

    One way is to use the metamodel:

    for (caseType in `class Suit`.caseTypes) {
        assert (is OpenClassOrInterfaceType caseType);
        print(caseType.declaration.name);
    }
    

提交回复
热议问题