07 Jul 2009 @ 8:42 PM 

I don’t know why, but the Enum class’ usefulness has always eluded me. Early attempts just didn’t work out, and I just found ways around using it. Recently, I am writing a program that needs to have a certain status be toggled between a known, fixed list of values-with a default value if nothing else matches. This real world project accelerated my learning how to use Enum effectively-much more so that the urgency to simply learn more about the language (i.e. no practical application of said knowledge).

I also wanted this magical class to determine for itself which value from the aforementioned list the thing that had the Enum in the first place should be. In other words, I wanted the method to do the determination to be inside the Enum class itself. I didn’t know if this was possible, but as I went over all the other ways to accomplish this, any other solution was too costly and inelegant.

To give you an idea of what I am trying to accomplish, consider this Test.java:

public class Test {
    public static void main(String[] args) {
        EventType etX = EventType.Default;
        EventType etY = EventType.Default;

        String sEvent = "this is just a test!";
        System.out.println("etX.getEventType: " + etX.getEventType(sEvent));
        etY = etX.getEventType(sEvent);
        System.out.println("print etX: " + etX);
        System.out.println("print etY: " + etY);
        System.out.println("All EventType(s):");
        EventType allEventTypes[] = EventType.values();
        for (EventType x: allEventTypes){
            System.out.println(x);
        }
    }
}

More »

Posted By: Pat
Last Edit: 13 Jul 2009 @ 01:04 AM

EmailPermalinkComments (0)
Tags
Categories: Java, Prog

 Last 50 Posts
 Back
 Back
Change Theme...
  • Users » 50
  • Posts/Pages » 174
  • Comments » 61
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

ATCP, LLC



    No Child Pages.

Factoid



    No Child Pages.