Java Enum Newbie Question

Posted by ikurtz on Stack Overflow See other posts from Stack Overflow or by ikurtz
Published on 2010-05-25T19:50:22Z Indexed on 2010/05/25 20:01 UTC
Read the original article Hit count: 213

Filed under:
|

i have a situation where i need the Checker enum below used in multiple classes:

package Sartre.Connect4;

public enum Checker {
    EMPTY,
    RED,
    YELLOW
}

so i put the Checker in a Checker.java file and then from the classes that need it i simply do the following:

example:

    public Cell(){

    currentCell = Checker.EMPTY;

}

example:

    public Cell(Checker checker){

    currentCell = checker;
}

and the code compiles fine and runs fine also.

so what is my question? well being new to Java i am just wondering if the way i use Checker without encapsulating it in a class is a sound implementation?

it may be because of The enum declaration defines a class (called an enum type). as noted in Java docs enum tutorial page.

thank you for your insight into this matter.

© Stack Overflow or respective owner

Related posts about java

Related posts about enum