ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Enums in Java (One More Time)
Subject:   enum-as-objects as array-index
Date:   2003-04-24 13:04:36
From:   anonymous2
Since the presented enums-as-objects pattern as an .ord() method which returns a unique int for each, I dispute that the pattern doesn't solve any part of #4 (efficiency for arrays/swithces).


Example:


Day day = Day.THURSDAY;
int[] countOnThatDay = ...;
int countOnThursday = countOnThatDay[day.ord()];


For a switch, one could get the integer value out, but not use the .ord() of each constant as a case value.


So, enums-as-objects, it seems to me, could solve half of #4.


1 to 1 of 1
  1. enum-as-objects as array-index
    2003-04-25 11:55:18  jimoore [View]

1 to 1 of 1