2

在我的项目中有超过 1000 种方法。我需要在所有这些中插入打印语句。

System.out.println(Thread.currentThread().getStackTrace()[1]);

是否有一种自动方法可以将该行插入我的项目中?

我使用 Netbeans IDE 7.3。

4

1 回答 1

1

As @no__seriously pointed out, the easiest way is using a smart regular expression or the find/replace function in your IDE.

A more sophisticated method is aspect oriented programming (AOP), which allows you to define aspects (think of it as hooks or jumppoints) in your software, e.g. before calling each method. One of the most used frameworks in Java is AspectJ. Depending on your demands, it is a much more complex way than regular expressions but provides a lot more flexibility.

于 2013-08-30T10:26:20.687 回答