user1798477
user1798477

Reputation: 31

java enum type getting a bit obfuscated

Hi I am practicing java enum these days and have been given the task of debugging some codes on these out of all i have found one very challenging here it is

public final class ParkingAttributes extends Enum
    {

    public static final ParkingAttributes BIKE;
    public static final ParkingAttributes CAR;
    public static final ParkingAttributes CYCLE;
    private static final ParkingAttributes ENUM$VALUES[];

    private ParkingAttributes(String s, int i)
    {
        super(s, i);
    }

    public static ParkingAttributes valueOf(String s)
    {
        return (ParkingAttributes)Enum.valueOf(com/tilzmatictech/mobile/navigation/delhimetronavigator/metro/ParkingAttributes, s);
    }

    public static ParkingAttributes[] values()
    {
        ParkingAttributes aparkingattributes[] = ENUM$VALUES;
        int i = aparkingattributes.length;
        ParkingAttributes aparkingattributes1[] = new ParkingAttributes[i];
        System.arraycopy(aparkingattributes, 0, aparkingattributes1, 0, i);
        return aparkingattributes1;
    }

    static 
    {
        CAR = new ParkingAttributes("CAR", 0);
        BIKE = new ParkingAttributes("BIKE", 1);
        CYCLE = new ParkingAttributes("CYCLE", 2);
        ParkingAttributes aparkingattributes[] = new ParkingAttributes[3];
        aparkingattributes[0] = CAR;
        aparkingattributes[1] = BIKE;
        aparkingattributes[2] = CYCLE;
        ENUM$VALUES = aparkingattributes;
    }
    }

One thing i know that enum is a final class and cannot be extended what i didnt find anywhere here is that enum be defined and work of ENUM$VALUES[] Can anyone explain me the working of this code and some good tutorials to master enum thanks.

Upvotes: 0

Views: 211

Answers (1)

Arnaud Denoyelle
Arnaud Denoyelle

Reputation: 31245

You are doing it wrong.

If you want to declare an enum, do it like this :

public enum ParkingAttributes { //Implicitly a final class that extends Enum
  BIKE, CAR, CYCLE//Implicitly static (but not final!) instances of ParkingAttributes.
}

Upvotes: 3

Related Questions