Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Java, is there a quick way to dump all arguments to a method?

Tags:

java

logging

I often find myself wanting to just print (using the implicit toString() of each object) every argument to a method in Java. Is there a quick way of accomplishing this?

like image 528
Christian Neverdal Avatar asked Jan 27 '12 01:01

Christian Neverdal


1 Answers

Java programming language doesn't have a construct to do this. However, you can do it with one of the AOP (Aspect Oriented Programming) packages, such as AspectJ.
In particular this thread might be a good starting point on how to achieve this:

http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg09939.html

My personal opinion, however, is that most of the time AOP is a scary overkill.

UPDATE: Oh, here's an easier way using Spring AOP, assuming you can use Spring. Generally, Spring is much easier to use than pure AspectJ.

like image 156
MK. Avatar answered Oct 17 '22 09:10

MK.