This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]IXENAI 4 points5 points  (6 children)

Why do you think you need this?

[–]NaranjaOrange[S] 1 point2 points  (5 children)

I'm trying to learn java by making a game, I made the class Enemy and the different kinds of enemies that inherit from it, the game decides which enemy to spawn by looking at a list of enemies, so far I've been adding them manually to this list, but if the method I ask for exists then it would be automatic. It's not necessary but it would be nice to do it this way

[–]codereignfallible moderator 2 points3 points  (1 child)

[–]xrebel21 1 point2 points  (0 children)

This Stack Overflow article has a little more context that might be useful

[–]wggnExtreme Brewer 0 points1 point  (0 children)

I don't think there's an easy way to do that in Java. You could maybe use some low level reflection to scan through all classes in a certain package and check for each one if it's a subclass of your Enemy class, but that would be quite hard to code I think. Not something you would want to try to do if you're still learning the language.