Specifications
Sun Services
Java™ Programming Language
Module 7, slide 17 of 44
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
Old-Style Enumerated Type Idiom
Old-style idiom is not type-safe:
0
1 package cards.tests;
2
3 import cards.domain.PlayingCard;
4
5 public class TestPlayingCard {
6 public static void main(String[] args) {
7
8 PlayingCard card1
9 = new PlayingCard(PlayingCard.SUIT_SPADES, 2);
10 System.out.println(“card1 is the “ + card1.getRank()
11 + “ of “ + card1.getSuitName());
12
13 // You can create a playing card with a bogus suit.
14 PlayingCard card2 = new PlayingCard(47, 2);
15 System.out.println(“card2 is the “ + card2.getRank()
16 + “ of “ + card2.getSuitName());
17 }
18 }










