Java object's reference namming

shim2k

Honorable
Aug 14, 2013
1
0
10,510
How to name an object in Java by a string variable?
For example:
createUsr(String s) { User s = new User();
For this example, the reference name would be "s" and not the value of the string s..
thanks!
 

randomizer

Distinguished
In every way that I can interpret what you are asking it is either impossible and/or pointless because the Java compiler must know the identifier at compile time. For starters, you can't have two identifiers with the same name in the same scope. Secondly, I can't see any reason to name one identifier after another, because even if it was possible it would be utterly confusing. Thirdly, even if you wanted the identifier to be named the same as the value of the string, this value is only known at runtime and the identifier doesn't exist at runtime so that doesn't even make sense.

Perhaps a more important question is "why do you want to do this?"