Enum converted to Class

14 February 2012 By Nithya Vasudevan 1,467 views One Comment
0 Flares Twitter 0 Facebook 0 Google+ 0 0 Flares ×

By using any Java Decompiler we can see what the enum converted class looks like.

Here we use Jad software for decompiling java class files.
Download Jad for your platform from this link – http://www.varaneckas.com/jad

Create a simple java file with the following code.

public enum PizzaSize

Save it as “PizzaSize.java” and compile using javac to PizzaSize.class.

From Command Prompt (or terminal in linux) in windows, go to the location of Jad directory and issue the following command.

jad.exe [Path to class file]

The output file will be created in the current directory (i.e.) the folder containing the jad.exe with extension .jad in our case it will PizzaSize.jad.

Open PizzaSize.jad in any text editor.

// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   PizzaSize.java

public final class PizzaSize extends Enum
    public static PizzaSize[] values()
        return (PizzaSize[])$VALUES.clone();

    public static PizzaSize valueOf(String s)
        return (PizzaSize)Enum.valueOf(PizzaSize, s);

    private PizzaSize(String s, int i)
        super(s, i);

    public static final PizzaSize SMALL;
    public static final PizzaSize MEDIUM;
    public static final PizzaSize LARGE;
    private static final PizzaSize $VALUES[];

        SMALL = new PizzaSize("SMALL", 0);
        MEDIUM = new PizzaSize("MEDIUM", 1);
        LARGE = new PizzaSize("LARGE", 2);
        $VALUES = (new PizzaSize[] {
            SMALL, MEDIUM, LARGE

You can see that the compiler has created values() and valueOf() method during this process.

Tags: , , , , ,