lonelyloner lonelyloner - 1 month ago 4
Java Question

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!

Answer

You are missing one tiny part of the Array declaration.

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