How can I get the name of a “String” variable/object returned to a usable string in my program ?

5 pts.
Tags:
Java
Java development
java script
String name
I have a function that takes "String arg1" as its single input argument. If I call this function passing a string myName to it to use as arg1, how can I get the characters "myName" stored in another string?

In other words, I need to extract the name of the variable/object being passed, not its contents.



Software/Hardware used:
Java

Answer Wiki

Thanks. We'll let you know when a new response is added.

Inside your function, there is no way to know that arg1 is receiving the value from a variable called ‘myName’.

Outside your function, you could probably use the reflection api if we were talking about class fields.

As for variable names, depending on how you compile your program, some debug information (including local variable names) could be stored in the .class file, but I don’t think it is going to be easy to read it from there.

Why do you need to do that ?

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • DinoKurt
    [...] How can I get the name of a String variable/object returned to a usable string in my program? asked by DinoKurt and answered by [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following