This question refers to version 1.2.1 and it doesn't compile at a different part so it's not a duplicate.
I want to use enums in Processing. I've read they work better in a separate file so I have done that. This code compiles correctly:
enum Status
{
STOPPED,MOVING
};
But when I have this code
Status status;
in a different file it gives me the following error:
Unrecognized type:46 (ENUM_DEF)
I know enums aren't supported in earlier versions of Processing but are they supported in version 2.0? If so what's cause the error?
Enums are lists of constants. When you need a predefined list of values which do represent some kind of numeric or textual data, you should use an enum. You should always use enums when a variable (especially a method parameter) can only take one out of a small set of possible values.
An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it. Common examples include compass directions (values of NORTH, SOUTH, EAST, and WEST) and the days of the week.
Enums limit you to the required set of inputs whereas even if you use constant strings you still can use other String not part of your logic. This helps you to not make a mistake, to enter something out of the domain, while entering data and also improves the program readability.
Because there is only one instance of each enum constant, it is permissible to use the == operator in place of the equals method when comparing two object references if it is known that at least one of them refers to an enum constant.
When you make a new tab for your enum, are you appending .java? In your case, is your new tab named Status.java?
Your code compiles fine for me in Processing 2.0b6 with the main tab contents:
Status status;
And a new tab named Status.java with the contents:
enum Status
{
STOPPED,MOVING
};
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