View Single Post
  #3   Spotlight this post!  
Unread 05-31-2010, 10:34 PM
LukeS LukeS is offline
4272 mentor, 1024 alumnus
AKA: Luke Shumaker
FRC #4272
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2009
Location: Indianapolis, IN
Posts: 60
LukeS is an unknown quantity at this point
Re: Porting to Java: enums, clocks, and multi-files

enums:

sunspotfrcsdk/lib/WPILibJ/enum.txt:
Code:
//Going to use this pattern for enumeration classes, since they are otherwise unsupported

//The typesafe enum pattern
public class Suit {
    public final int value;

    protected static final int CLUBS_VAL = 0;
    protected static final int DIAMONDS_VAL = 1;
    protected static final int HEARTS_VAL = 2;
    protected static final int SPADES_VAL = 3;

    public static final Suit CLUBS = new Suit(CLUBS_VAL);
    public static final Suit DIAMONDS = new Suit(DIAMONDS_VAL);
    public static final Suit HEARTS = new Suit(HEARTS_VAL);
    public static final Suit SPADES = new Suit(SPADES_VAL);

    private Suit(int value){
        this.value = value;
    }
}
WPILIB uses this method throughout, and I used it in our bot.

Classes in one file:
Don't. Trust me, I know where you're coming from, I was there once. You're trying to program in some other language. Wrap your mind around Java, and then, this will seem stupid.

However, you may be interested to know that you can define sub-classes, which are all in the same file.
Reply With Quote