Initializing/adressing an object via string
in
Programming Questions
•
2 years ago
Let's say I've got a String
- String string1="myCar_1";
In the end I want to do this:
- myCar_1.drive();
But I want to do this using the string I have. Something along the lines of string1.drive() - which I know is impossible.
I know that this has something to do with Java's
reflection and methods such as
newInstance() and
forName() but I don't understand the examples I've found already.
1