enum.values() - 是返回的枚举确定性的顺序 [英] enum.values() - is an order of returned enums deterministic

查看:596
本文介绍了enum.values() - 是返回的枚举确定性的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个枚举 SOME_ENUM

public enum SOME_ENUM {
  EN_ONE,
  EN_TWO,
  EN_THREE;
}

SOME_ENUM.values()总是以枚举声明的顺序返回枚举:
EN_ONE,EN_TWO,EN_THREE ?这是一个规则还是不能保证在下一个JDK版本中不会更改?

Will SOME_ENUM.values() always return the enums in the order of enum declarations: EN_ONE, EN_TWO, EN_THREE? Is it a rule or it is not guaranteed to be not changed in the next JDK releases?

推荐答案

Java语言规范使用这种显式语言:

The Java language specification uses this explicit language:


@返回一个包含这个枚举类型的常量的数组,按照它们被声明的顺序 [来源]

所以是的,他们将以申报令退回。值得注意的是,如果有人更改课程,那么订单可能会随着时间的推移而改变,以便如何使用该课程非常小心。

So, yes, they will be returned in declaration order. It's worth noting that the order might change over time if someone changes the class so be very careful about how you use this.

这篇关于enum.values() - 是返回的枚举确定性的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆