公共枚举中的主要方法 [英] main method in a public enum
本文介绍了公共枚举中的主要方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法编译.
public enum Days{ monady(1), tuesday(2), wedenesday(3), thursday(4), friday(5), saturday(6), sunday(7); private final int dayValue; Days(int count) { this.dayValue=count; } public int getDayValue() { return dayValue; } public static void main(String[] args) { for(Days day:Days.values()) { System.out.println("The day is "+day+" ,The value of day is:"+day.getDayValue()); } } }
解决方案
我刚刚编译并运行了此代码,没有任何问题.尝试时究竟发生了什么?
我认为除了enum
中的常量之外,您实际上不能定义任何其他东西.我可能是错的,但是这些教程似乎与我一致:枚举类型 [ ^ ]
因此,尝试将整个程序包含在enum
中总是会以眼泪结束...
hi
what is wrong with this code?
i can not compile it.
public enum Days{ monady(1), tuesday(2), wedenesday(3), thursday(4), friday(5), saturday(6), sunday(7); private final int dayValue; Days(int count) { this.dayValue=count; } public int getDayValue() { return dayValue; } public static void main(String[] args) { for(Days day:Days.values()) { System.out.println("The day is "+day+" ,The value of day is:"+day.getDayValue()); } } }
解决方案
I have just compiled and run this code without problems. What exactly happens when you try?
I don''t think you can actually define anything other than constants in anenum
. I could be wrong, but the tutorials seem to agree with me: Enum Types[^]
So trying to include your whole program in anenum
is always going to end in tears...
这篇关于公共枚举中的主要方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文