3

最近有人告诉我,如果您查看 Java 程序的调试信息,您可以获得比反射更多的信息。我意识到虽然我真的不知道什么,也许除了内存位置等。那么通过反射无法获得的调试信息还能得到什么(注意:我不是在谈论使用断点来获取实际的运行时值)?是否有任何信息可以通过反射获得而您无法从调试器中获得?

4

1 回答 1

1

im going to assume that by "with debugger information" you actually mean "using the agent API", which is what debuggers (among others) use.

the answer is quite a lot.

for startes the JVMTI can force garbage collection, which no pure java API can. this can, for specific types of applications and contrary to common wisdom, be useful at times even for "production" code.

you could also instrument classes as they load. this is useful for various profiler tools, obfuscation of your compiled code (encrypted class files) and even changing loaded classes on the fly in response to changes in source code (see jrebel for a good example)

于 2013-06-28T15:01:10.937 回答