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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.