I use a method to collect all classes from a package and save them into an array:
Class[] classes = ClassUtils.getClasses("xyz.keahie.werewolf.character.characters");
They all have the class "Character" as superclass and when I print them I get this line:
class xyz.keahie.werewolf.character.Character
When I want to cast them to the class "Character" I always get an ClassCastException. What am I doing wrong?
Edit: Here is the full Error which I get:
Exception in thread "main" java.lang.ClassCastException: java.lang.Class cannot be cast to xyz.keahie.werewolf.character.Character
at xyz.keahie.werewolf.character.CharacterManager.<init>(CharacterManager.java:29)
at xyz.keahie.werewolf.GameManager.<init>(GameManager.java:26)
at xyz.keahie.werewolf.Game.main(Game.java:9)
And here my source code:
Class[] classes = ClassUtils.getClasses("xyz.keahie.werewolf.character.characters");
for (Class clazz : classes) {
Object object = clazz.getSuperclass();
System.out.println(object.toString());
if (object.getClass().equals(xyz.keahie.werewolf.character.Character.class)) {
System.out.println("Yes");
} else {
System.out.println("Nope");
}
Character character = (Character) object;
if (!this.characters.contains(character)) {
addSpecialCharacter(character);
}
}
Sorry for the missing information at the begin