dimanche 22 février 2015

Reflection Java assistance

I have a reflection thing that goes out and finds all classes with an annotation called @Song and a name of charge. How would I make this go into org.alexwebber.songs and find all the classes with @Song and get all their names into a array? Thanks!



new Reflections("org.alexwebber.musicMaker.songs").getTypesAnnotatedWith(Song.class);
for ( Class<?> cls : new Reflections("org.alexwebber.musicMaker.songs").getTypesAnnotatedWith(Song.class) ) {
Song annotation = (Song) cls.getDeclaredAnnotation(Song.class);
if ( annotation != null && annotation.Name().equals("Charge")) {
@SuppressWarnings("unused")
Object song = cls.getConstructor().newInstance();
break;
}





Aucun commentaire:

Enregistrer un commentaire