Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

这一段写的感觉有点问题,疑问在最后 #159

Open
wuzhidexiaolang opened this issue Aug 16, 2019 · 0 comments
Open

这一段写的感觉有点问题,疑问在最后 #159

wuzhidexiaolang opened this issue Aug 16, 2019 · 0 comments

Comments

@wuzhidexiaolang
Copy link

Rule 5. 【推荐】如果变量值仅有有限的可选值,用枚举类来定义常量

尤其是变量还希望带有名称之外的延伸属性时,如下例:

//WRONG
public String MONDAY = "MONDAY";
public int MONDAY_SEQ = 1;

//RIGHT
public enum SeasonEnum {
SPRING(1), SUMMER(2), AUTUMN(3), WINTER(4);
int seq;
SeasonEnum(int seq) { this.seq = seq; }
}
默认的default的访问域是不能跨包的,如果枚举类放在基础包下的话,seq的访问就无法生效了。所以感觉这里写的不够严谨。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant