Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #34216

Re: Need to get the variable name from the called method

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Need to get the variable name from the called method
Date 2016-04-28 13:31 -0400
Organization A noiseless patient Spider
Message-ID <nfth7u$vqo$1@dont-email.me> (permalink)
References <8735ea75-7793-49ad-a31d-ebf6c2691bac@googlegroups.com>

Show all headers | View raw


On 4/28/2016 11:16 AM, saransamurai7@gmail.com wrote:
> Code:
>
> class Test {
>
> public static void main(String args[]) {
>
> int valueInt = 10;
>
> function(valueInt);
>
> }
>
> void function(int param) {
>
> // Here I need to get the output as "valueInt" & not 10.
>
> }
>
> Kindly help me to get the variable name "valueInt" to be printed inside the method 'function'

     Why?

     With a *lot* of *hard* work you *might* be able to discover the
string "valueInt" -- you'd probably need to find the caller (which
might be in a method of some completely different class), disassemble
that class' bytecodes, work your way backwards to the .class file from
which they came (if one exists), and hope there's enough ancillary
debugging information lying around in the .class file, and then ...

     ... of course, all this may come to naught if there is *no* name
corresponding to the argument, as in

	function(valueInt ^ 42);

     So, again: Why do you want to do this?  Are you hoping to get

	function(valueInt);
	function(otherInt);
	function(intangible);

to print something like

	valueInt = 10
	otherInt = 42
	intangible = -99193

?  What's your goal?

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Need to get the variable name from the called method saransamurai7@gmail.com - 2016-04-28 08:16 -0700
  Re: Need to get the variable name from the called method Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-04-28 13:31 -0400
  Re: Need to get the variable name from the called method Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-04-29 08:41 +0200
    Re: Need to get the variable name from the called method Lew <lewbloch@gmail.com> - 2016-04-29 11:18 -0700
      Re: Need to get the variable name from the called method Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-04-29 20:52 +0200

csiph-web