0
How to scan a string and use that as new object name?
For example: Scanner scan = new Scanner(system.in) String str = sc.next(); Now i would like to make an object name based on the input... A str = new A(); How? To make an object name based on str input?
4 ответов
+ 4
This is an interesting question. But in Java it does not work. If I'm right, the name of a variable is not a datatype.
https://stackoverflow.com/questions/26541743/create-variables-dynamically-data-types-of-java-variables/26541997#26541997
The only thing I can imagine would be to use an other language which creates java code.
+ 2
Alright thx guys i will try it
+ 1
You can create an String object:
String s = new String(str);
+ 1
use Map<String, Object> or HashMap<String, Object> instead