关于Java中的access方法的一点零散笔记
在研究一个NPE的stack trace的时候,发现一个方法名是access$1100,隐约感觉是一个synthesized的东西,但不知道其确切来历。在网上搜了一下,发现如下一篇文章:
http://www.retrologic.com/innerclasses.doc7.html
其中主要是如下一段话大概解答了我的疑问:
There is one more category of compiler-generated members. A private member m of a class C may be used by another class D, if one class encloses the other, or if they are enclosed by a common class. Since the virtual machine does not know about this sort of grouping, the compiler creates a local protocol of access methods in C to allow D to read, write, or call the member m. These methods have names of the form access$0, access$1, etc. They are never public. Access methods are unique in that they may be added to enclosing classes, not just inner classes.
至此,对于这个问题还是一知半解,先在这里发一篇,回头有空再来补一补