在研究一个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.
至此,对于这个问题还是一知半解,先在这里发一篇,回头有空再来补一补 :arrow:
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.
至此,对于这个问题还是一知半解,先在这里发一篇,回头有空再来补一补 :arrow:
本文探讨了在Java中由编译器生成的特殊方法access$nnn的用途与含义。这类方法通常用于实现内外类之间的访问控制,确保内部类可以访问外部类的私有成员,同时对外部世界保持封装。
717

被折叠的 条评论
为什么被折叠?



