N*n 发帖数: 456 | 1 Is it possible to make a dump method in Java, so that when it's called, it
will find out all the variables, methods info, even codes, then output it? I
want it to be a general method, which means the same code working for most
object. It would be better to provide the current variable value.. Are there
such method? Or is it possible?
Thanks! | T*********g 发帖数: 496 | 2 线程的stack trace你可以拿到,变量值不行。
I
most
there
【在 N*n 的大作中提到】 : Is it possible to make a dump method in Java, so that when it's called, it : will find out all the variables, methods info, even codes, then output it? I : want it to be a general method, which means the same code working for most : object. It would be better to provide the current variable value.. Are there : such method? Or is it possible? : Thanks!
| N*n 发帖数: 456 | 3 谢谢。。找了点code在看。。
public class StackTraceExample
{
//private static final Logger logger = Logger.getLogger(StringReplace.class.
getName());
public static void main(String args[])
{
//calling a method to print stack trace further down
first();
}
public static void first()
{
second();
}
private static void second()
{
third();
}
private static void third()
{
//If you want to print stack trace on console than use dumpStack() method
System.err.println("Stack trace of current thread using dumpStack() method
");
Thread.currentThread().dumpStack();
//This is another way to print stack trace from current method
System.err.println("Printing stack trace using printStackTrace() method of
Throwable ");
new Throwable().printStackTrace();
//If you want stack trace as StackTraceElement in program itself than
//use getStackTrace() method of Thread class
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
//Once you get StackTraceElement you can also print it to console
System.err.println("displaying Stack trace from StackTraceElement in Java"
);
for(StackTraceElement st : stackTrace)
{
System.err.println(st);
}
}
}
【在 T*********g 的大作中提到】 : 线程的stack trace你可以拿到,变量值不行。 : : I : most : there
| s****l 发帖数: 600 | 4 aop?
I
most
there
【在 N*n 的大作中提到】 : Is it possible to make a dump method in Java, so that when it's called, it : will find out all the variables, methods info, even codes, then output it? I : want it to be a general method, which means the same code working for most : object. It would be better to provide the current variable value.. Are there : such method? Or is it possible? : Thanks!
| T*********g 发帖数: 496 | 5 不可能的。就算可以,这个cost高的让你根本没办法用。
【在 s****l 的大作中提到】 : aop? : : I : most : there
| N*n 发帖数: 456 | 6 AOP?
Aspect Oriented Programming?
First time knowing it..
【在 T*********g 的大作中提到】 : 不可能的。就算可以,这个cost高的让你根本没办法用。
| l**********n 发帖数: 8443 | 7 you can use interceptor.
【在 N*n 的大作中提到】 : AOP? : Aspect Oriented Programming? : First time knowing it..
| D*****d 发帖数: 1307 | 8 reflection?
I
most
there
【在 N*n 的大作中提到】 : Is it possible to make a dump method in Java, so that when it's called, it : will find out all the variables, methods info, even codes, then output it? I : want it to be a general method, which means the same code working for most : object. It would be better to provide the current variable value.. Are there : such method? Or is it possible? : Thanks!
|
|