[Solved] java dynamic class instance creation


If you need to dynamically create new objects and assign them to a variable, I would utilize a map with the key used to simulate naming a variable and the value as the newly created Chicken object: e.g.

    new HashMap<nameOfVariable, Chicken>() 

This will get you around not knowing the number or name of your instances at runtime. For example, if you were reading in a file from a user that was a list of named Chicken objects.

solved java dynamic class instance creation