Simply unpacks an enumerated type for a given integer. - Android java.lang

Android examples for java.lang:Enum

Description

Simply unpacks an enumerated type for a given integer.

Demo Code


//package com.java2s;

public class Main {
    /**//from w ww. ja v  a  2 s  . co m
     * Simply unpacks an enumerated type for a given integer.
     * @param value An enumerated type expressed as an int
     * @param aClass The enumerated type in question
     * @return The corresponding enumerated type for the given integer
     */
    public static <T extends Enum<?>> T forInt(int value, Class<T> aClass) {
        return aClass.getEnumConstants()[value];
    }
}

Related Tutorials