Getting static member from Field
Hello,
I have a 'static type safe enum class' and I want to use reflection to implement its toString() method, the String returned should be the name of the field.
(Note that the static instance variables themselves do not have String fields that could be used for the toString() return value.)
I am able to iterate through all fields of the class and print out the names using getName()
But not sure how to compare the types of the fields to a particular type. For example:
for (int i = 0; i < fields.length; i++)
{
Field field = fields;
// how to compare a field to know if it is a
// particular static instance field
if (field.getType().equals(MyEnum.A_STATIC_INSTANCE))
{
return field.getName();
}
}

