J
josef
class A<T extends Enum<T>> {
Class<T> e;
public A(Class<T> type) {
e = type;
}
public T get(int ordinal) {
/*
* Is there a better (faster) way to access the implicitly declared
* static method 'values' (1) for enums (i.e. without reflection)?
*
* (I'm trying to implement a sweet ComboboxModel)
*
* (1)
http://java.sun.com/docs/books/jls/third_edition/html/classes.html#302265
*/
try {
return ((T[])e
.getDeclaredMethod("values", new Class[]{})
.invoke(null, new Class[]{}))[ordinal];
} catch(Exception ex) {
//method is static and defined in java language specification
}
throw new AssertionError();
}
}
Class<T> e;
public A(Class<T> type) {
e = type;
}
public T get(int ordinal) {
/*
* Is there a better (faster) way to access the implicitly declared
* static method 'values' (1) for enums (i.e. without reflection)?
*
* (I'm trying to implement a sweet ComboboxModel)
*
* (1)
http://java.sun.com/docs/books/jls/third_edition/html/classes.html#302265
*/
try {
return ((T[])e
.getDeclaredMethod("values", new Class[]{})
.invoke(null, new Class[]{}))[ordinal];
} catch(Exception ex) {
//method is static and defined in java language specification
}
throw new AssertionError();
}
}