Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Question...

Status
Not open for further replies.

Raven123

Programmer
Joined
Mar 8, 2001
Messages
9
Location
US
Hello,

I am moving to Java from Delphi and have a question...

In Delphi, it's legal to create enumerated types like:

type Suit = (Club, Diamond, Heart, Spade);

which defines an enumerated type called Suit whose possible values are Club, Diamond, Heart, and Spade.... Therefore, when I create a variable of type 'Suit', it has to be one of these values (or nil).

How do I re-create this behavior in Java?

Thanks in advance for any help.

Rich.
 
String suit = {"Diamonds, "Hearts" etc}

I do not know Delphi so I may have misunderstood your question.
 
Hi Raven123,
You can create a class as follows
class Cards {
private String value;
private Cards(String value) {
this.value = value;
}
public String getValue() {
return value;
}
public static final Cards CLUB = new Cards("Club");
public static final Cards DIAMOND = new Cards("Diamond");
public static final Cards HEART = new Cards("Heart");
public static final Cards SPADE = new Cards("Spade");
}
And in the application you can use it as,
Cards cardVar = Cards.CLUB;
and you can access the value stored as,
System.out.println(cardVar.getValue());

Hope this helps you.
Regards,
Rajarajan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top