enum.values() - is an order of returned enums deterministic

后端 未结 4 1048
傲寒
傲寒 2020-12-07 19:44

I have a enum SOME_ENUM:

public enum SOME_ENUM {
  EN_ONE,
  EN_TWO,
  EN_THREE;
}

Will SOME_ENUM.values() alway

4条回答
  •  时光取名叫无心
    2020-12-07 20:14

    Yes, it is a guaranteed to return them in that order.

    However you should avoid relying on that, and on the ordinal() value, since it can change after inserting new items, for example.

提交回复
热议问题