0

I'm wondering if anybody knows a way to dynamically create a Java class, or more specifically a method in a Java class. I'm trying to do some unit testing, so I have code that I've already written, and I'm always modifying the code by adding extra System.out.println statements and then deleting them when I'm finished (otherwise the code gets too cluttered). What I'm trying to do is write a framework that can take a method, copy its code, add the System.out.println statements automatically, and then run the test on the copied method. This might also save time recompiling an entire Java application when I've only made a minor change to get some extra info while debugging.

Any ideas would be greatly appreciated.

0

4 Answers 4

2

You could just use a logging framework.

Sign up to request clarification or add additional context in comments.

Comments

1

Sounds like you need aspects, i.e. AspectJ.

Comments

1

One option is to use cglib (Code Generation Library).

Comments

0

I don't have a specific example, but Aspect Oriented Programming (AOP) is what you want. Take a look at AspectJ.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.