Chr*_*ght 5 java eclipse compiler-warnings java-synthetic-methods
我有以下代码:
public class SomeClass {
//InterfaceUpdateListener is an interface
private InterfaceUpdateListener listener = new InterfaceUpdateListener(){
public void onUpdate() {
SomeClass.this.someMethod(); //complier complains on this line of code
}
};
private void someMethod() {
//do something in here on an update event occuring
}
//other code to register the listener with another class...
}
Run Code Online (Sandbox Code Playgroud)
我在 Eclipse 中的编译器抱怨说
Access to enclosing method 'someMethod' from type SomeClass is emulated by a synthetic accessor method.
谁能准确解释一下
谢谢
我只是停用该规则(即使编译器不为此生成警告)。如果构造是合法的,并且编译器添加了额外的方法来支持它,那么它就必须这样做。
我怀疑这种合成方法会造成性能的显着损失。如果有必要,JIT 无论如何都必须内联它。