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!
You can iterate through an enum to access its values. The static values() method of the java. lang. Enum class that all enums inherit gives you an array of enum values.
This way I can write a functions in which I can pass the array index into for setting particuler values of the enum. Updated: Here is an example of what I am wanting to do. [flag] enum1(value1=0, value2=1, value3=2, value4=4...)
Enums don't have methods for iteration, like forEach() or iterator(). Instead, we can use the array of the Enum values returned by the values() method.
An enumeration (enum for short) in Java is a special data type which contains a set of predefined constants. You'll usually use an enum when dealing with values that aren't required to change, like days of the week, seasons of the year, colors, and so on.
You are missing one tiny part of the Array declaration.
_machines = new Machine[]{Machine.a, Machine.b};
This can also be declared empty at first if you give it a size.
_machines = new Machine[size];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With