Getting all inner classes by reflection
Posted
by Roman
on Stack Overflow
See other posts from Stack Overflow
or by Roman
Published on 2010-05-24T18:14:49Z
Indexed on
2010/05/24
18:21 UTC
Read the original article
Hit count: 162
java
I have the following problem. I have this pretty class and now I want to get all the classes that extend that class (inner classes ) and fill 'classList' with it. ( in an automatic way of course )
public abstract class CompoundReference {
private static List<Class<? extends CompoundReference>> classList
= new ArrayList<Class<? extends CompoundReference>>();
@CompoundKey(gsType = User.class, dbType = UserDetailsMappings.class)
public static class CUser extends CompoundReference {
}
@CompoundKey(gsType = Catalog.class, dbType = CatalogDetailsMappings.class)
public static class CCatalog extends CompoundReference {
}
@CompoundKey(gsType = Product.class, dbType = ProductDetailsMappings.class)
public static class CProduct extends CompoundReference {
}
@CompoundKey(gsType = Category.class)
public static class CCategory extends CompoundReference {
}
@CompoundKey(gsType = Poll.class, dbType = PollDetailsMappings.class)
public static class CPoll extends CompoundReference {
}
// much mroe inner classes
Some manual solution would be just to main such a static block , that is something that I dont want to do.
static {
classList.addAll(Arrays.asList(CUser.class, CCatalog.class,
CProduct.class, CCategory.class,
CPoll.class, CComment.class, CWebPage.class,
CReview.class, CPost.class, CMessage.class, CStory.class,CPicture.class));
}
© Stack Overflow or respective owner