• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting Values of Parameters to Method  RSS feed

 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Ranchers,

I have to grab values and names of all the parameters to current method using some generic way, is this possible in java? I used following code to grab method name and class name.




-P
[ August 20, 2008: Message edited by: Praful Thakare ]
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand you correctly, the only thing that would have something like this would be the Reflection classes (java.lang.reflect.*). These classes give you the ability to examine your own code and get data on it, hence the term "Reflection".
 
Praful Thakare
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i stuggle to find reflection helpful here, it will be handy when i load a method using name and pass parameters to it, but my requirement is to get the CURRENT method parameter those are passed to method.


-P
 
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume in your call stack you want to know what were the method arguments and values 2 level above in the stack.

May I know, why do you want to do that?

If this is a part of your business logic, then i am afraid it is a terribly bad way of doing it. The correct way is to explicitly pass the arguments.

If this is some sort of debug then you may be better off attaching a debugger than to do all this.

If this is for logging, then either you should modify the code to log the arguments or if you want to do it differently(i.e. you want to add/remove code at will) you can look the a technology called AOP(Aspect oriented programming)

Am i missing something?
 
Praful Thakare
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>>>>>Am i missing something?

yes, the solution to my problem

I have 1000's of methods those needs a modification to call one util method and pass method name and parameters in error condition and yes for logging.

And if I find way to grab this in generic way then i an modify all these methods in fraction on seconds else it will take loads of efforts.
-P
[ August 22, 2008: Message edited by: Praful Thakare ]
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praful:
yes, the solution to my problem

I am afraid that in order to get a solution you need to explain your problem clearly
As a matter of fact, I was not giving a solution, I was trying to find out the problem! Whatever little I understood things looked hopelessly wrong
Anyways, Here are my 2 cents.

Praful:
And if I find way to grab this in generic way then i an modify all these methods in fraction on seconds else it will take loads of efforts.


Information about the local variables are present in the method stack and are not available using the standard JDK apis.
This information is typically available via Java debugging technology(JPDA)
I am sure you do not want to introduce one more technology(if at all you can) for saving the pain of modifying thousands of files.
(After all, if you use an ide, it should not take you more than a day)

In a nutshell, I do not know(and i am some what confident that there is none) a straight forward way of doing this.

-------------

"It gives pleasure to write magical code but in most of the time it categorizes as "over-engineering"
 
Praful Thakare
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sure you do not want to introduce one more technology


Of course not.

Thanks for your time anyways.

-P
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!