Is it possible to get a class type from inside a static initialization block?
This is a simplified version of what I currently have:
class Person extends SuperClass {
String firstName;
static{
doSomeReflectionStuff(Person.class);
}
}
This is closer to what I am doing, it is initializing a data structure that contains information about the object and its annotations, etc. Maybe I'm using the wrong template?
public abstract SuperClass{
static void doSomeReflectionStuff( Class<?> classType, List<FieldData> fieldDataList ){
Field[] fields = classType.getDeclaredFields();
for( Field field : fields ){
}
}
}
public abstract class Person {
@SomeAnnotation
String firstName;
static List<FieldData> fieldDataList = new List<FieldData>();
static{
doSomeReflectionStuff(Person.class, fieldDataList);
}
}
Edit
I chose the accepted answer based on what is best applicable to my problem, however it seems to me that all three of the current answers have their merits.
source
share