Changing enum values
<p>Why does the following code throw an exception? </p>

<p>I need to persist enum values, and I am guessing the best practice for persisting the enum values in database is to store them as lower case string literals and hence this effort.</p>

<pre><code>public enum Type {

SWIPE_BUTTON("swipe_button"), DROP_DOWN("drop_down"), RADIO_BUTTON("radio_button"), CHECK_BOX("check_box");

private final String label;

private Type (String label) {
    this.label = label;
}

public String getValue() {
    return label;
}

@Override
public String toString() {
    return getValue();
}

public static Type getEnum (String value) {

    for (Type type : values())
        if (type.getValue().equals(value)) return type;

    throw new IllegalArgumentException("invalid value for type");
}

public static void main (String[] args) {

    System.out.println(Type.valueOf("swipe_button"));
}
}
</code></pre>

<p>I found this approach <a href="https://stackoverflow.com/questions/9662170/override-valueof-and-tostring-in-java-enum">here</a>.</p>

<p><strong>UPDATE</strong></p>

<p>Looks like I was essentially trying to override the <code>valueOf</code> method, and the answer is it is not possible to do so. I was trying to override this method so that when my JPA database mapper tries to auto populate the entity object from database I can convert the lower-cased string literals (in database) to their uppercased enum constants. I shall retort to persisting the enums with their names itself (i.e. uppercased).</p>