Let's say I have this class below:
public class Player{
}
I could make a new instance of it like this:
Player someone = new Player();
Now I have a .txt file with each line as a potential player:
george
joel
kate
...
I can read these lines and assign them to a String like this:
String name = "george";
How could I make a new Player with the name of "george"? For example, I would like to create "george" down below.
Player name.toClassName = new Player();
One solution I found would be:
if(name == "george"){
Player george = new Player();
}
if(name == "joel"){
Player joel = new Player();
}
if(name == "kate"){
Player kate = new Player();
} ...
But this above just looks stupid. (By the way I already have a private name; inside the Player class, I am assigning those Strings to them after the instances are made, I can get and set them etc. but that is not what I would like to manipulate with here. I'm just interested if you could make new instances this way.