We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
no Enum Types ? (Read 794 times)
no Enum Types ?
Jun 26th, 2007, 9:16pm
 
Am I right saying Enum types are not available in Processing?

I mean something like the following:

public enum Day {
   SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
   THURSDAY, FRIDAY, SATURDAY
}
Re: no Enum Types ?
Reply #1 - Jun 26th, 2007, 9:53pm
 
From wikipedia (so it must be true):

Java

The J2SE version 5.0 of the Java programming language added enumerated types whose declaration syntax is similar to that of C's:
Code:

enum Cardsuit { Clubs, Diamonds, Spades, Hearts }
...
Cardsuit trump ;

The Java type system, however, treats enumerations as a type separate from integers, and intermixing of enum and integer values is not allowed (except that you can retrieve the integer out of an enum value using the .ordinal() method). In fact, an enum type in Java is actually a special compiler-generated class rather than an arithmetic type, and enum values behave as global pre-generated instances of that class. Enum types can have instance methods and a constructor (the arguments of which can be specified separately for each enum value). All enum types implicitly extend the Enum abstract class. An enum type cannot be instantiated directly.


The version of Java is of note here. For installation specific purposes you may be fine - don't depend on all of your users having Java 5.0 or later. And you may want to look in the Processing FAQ regarding Java versions.
Re: no Enum Types ?
Reply #2 - Jun 28th, 2007, 7:20am
 
This doesn't work.

I am using Basic and Continuous programming mode,
as defined in http://processing.org/reference/environment/index.html

I guess I should switch to Java mode to make it work.
Re: no Enum Types ?
Reply #3 - Jun 28th, 2007, 11:07am
 
alphachapmtl wrote on Jun 26th, 2007, 9:16pm:
Am I right saying Enum types are not available in Processing

I mean something like the following:

public enum Day {
   SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
   THURSDAY, FRIDAY, SATURDAY
}



I guess more java-1.4-conform methods like these will work:

String[] DAYS;
void setup() {
DAYS=new String[7];
DAYS[0]= "SUNDAY";
...(dont forget to fill the arr)
DAYS[6]="SATURDAY";
}
public String[] getDays() {
return DAYS;
}
public String getDay(int indx) {
return DAYS[indx];
}

If you want to use a container with mixed objs (like String, Diamond, Blood ...) use e.g. ArrayList.
Page Index Toggle Pages: 1