简体   繁体   中英

Java array of enum values

Machine is defined as public enum Machine{...}

_machines is defined as 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!

您缺少Array声明的一小部分。

_machines = new Machine[]{Machine.a, Machine.b};

如果你给它一个大小,这也可以在最初被声明为空。

_machines = new Machine[size];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM