枚举值的 Java 数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4206586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java array of enum values
提问by Dustin Sun
Machine is defined as public enum Machine{...}
机器定义为 public enum Machine{...}
_machines
is defined as private Machine[] _machines;
_machines
被定义为 private Machine[] _machines;
Don't know why this doesn't work:
不知道为什么这不起作用:
_machines = {Machine.a, Machine.b};
error message:
错误信息:
illegal start of expression
表达式的非法开始
Thank you guys!
谢谢你们!
采纳答案by jjnguy
You are missing one tiny part of the Array declaration.
您遗漏了 Array 声明的一小部分。
_machines = new Machine[]{Machine.a, Machine.b};
回答by JG007
This can also be declared empty at first if you give it a size.
如果给它一个大小,它也可以首先声明为空。
_machines = new Machine[size];