lonelyloner lonelyloner - 1 year ago 113
Java Question

Java array of enum values

Machine is defined as

public enum Machine{...}

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!

Answer Source

You are missing one tiny part of the Array declaration.

_machines = new Machine[]{Machine.a, Machine.b};
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download