什么是“内部类仿真”?在Java中?
在阅读 eclipse JDT 的文档时刚刚发现了这一点:
IMethodBinding.getParameterTypes()
: . 。 。 注意:结果不包括内部类仿真引入的综合参数。
我在 JLS 中找不到任何对内部类仿真的引用...有人知道这个仿真是什么吗?举一个例子,也会有帮助。 :)
just found this bit, while reading eclipse JDT's documentation:
IMethodBinding.getParameterTypes()
: . . .
Note: The result does not include synthetic parameters introduced by inner class emulation.
I can't find any reference to inner class emulation in JLS... Anyone knows what this emulation is? Throwing an example, would help as well. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 Eclipse 文档编写者对术语的理解有点松散。就 JLS 而言,内部类就是内部类,不需要模拟。
然而,典型 JVM 实现内部类的方式有一点棘手,这就是合成构造函数参数的作用。发生的事情是,无论是否嵌套,JVM 都会以相同的方式实现类。没有特殊的字节码用于引用封闭类中的变量,因此编译器生成通过合成属性获取它们的代码。
更多细节可以在原始的 Sun Java 1.1 内部类规范。
I think that the Eclipse documentation writer being a little bit loose with the terminology. As far as the JLS is concerned, an inner class is an inner class and doesn't need to be emulated.
However, there is a bit of trickiness in the way that inner classes get implemented by a typical JVM, and this is where the synthetic constructor parameters come into the equation. What is going on is that the JVM implements classes the same whether they are nested or not. There are no special bytecodes for referring to variables in enclosing classes, so the compilers generate code that fetch them via the synthetic attributes.
More details may be found in the original Sun Java 1.1 Inner Classes Specification.
我怀疑“内部类模拟”意味着编译器如何为内部类生成字节码。
虚拟机级别没有内部类支持(至少在引入它们时)。编译内部类时,编译器必须为普通类生成字节代码。添加对外部类实例的引用,例如:
内部类被编译为类似以下内容的内容:
I suspect that “inner class emulation” is meant to be how the compiler generate the byte code for inner classes.
There is no inner class support at virtual machine level (at least when they got introduced). The compiler must generate byte code as for a normal class when compiling an inner class. Adding a reference to the outer class instance, for example:
the Inner class get compiled to something similar to: