Hello all,
I’m just wondering if it’s possible to create an object from a variable String. For example, I have four classes named Tile1, Tile2, …, etc. Now say I have a String, from which an ID character (1 - 4) is incremented into the String, could I create a class-object from that String? Like so:
char id = '2'; // This character is arbitrary in my actual program, but just initiated as '2' for this example.
String name = "Tile"+id;
Tile t = new name(); // All Tile1...4 classes extend the main class, Tile.
Of course, the code above doesn’t work because the compiler thinks I’m trying to create an object of class name, which doesn’t exist. But is there any possible way to create an object of a class from a String, like above?