如何避免使用inline-anonymous类声明的综合访问编译器警告,这是什么意思? [英] How can I avoid synthetic access compiler warning with inline-anonymous class declaration and what does it mean?

查看:140
本文介绍了如何避免使用inline-anonymous类声明的综合访问编译器警告,这是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

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...
}

我的Eclipse编译器抱怨说

My compiler in Eclipse complains that


从类型SomeClass访问封闭方法'someMethod'是由一个综合访问器方法来模拟的。 / p>

Access to enclosing method 'someMethod' from type SomeClass is emulated by a synthetic accessor method.

任何人都可以解释


  1. 这是什么意味着

  2. 如果我离开它(因为它只是一个警告),可能的后果可能意味着什么,而

  3. 我该如何解决它

谢谢

推荐答案

我只会停用规则(即使编译器不会为此产生警告)。如果构建是合法的,并且如果编译器添加了一个额外的方法来支持它,那么它是必须完成的。

I would just deactivate the rule (i.e. make the compiler not generate warning for this). If the construction is legal, and if an additional method is added by the compiler to support it, then it's the way it must be done.

我怀疑这种合成方法造成的性能显着下降。必要时,JIT必须内联它。

I doubt there is a significant loss of performance caused by this synthetic method. The JIT must inline it anyway if necessary.

这篇关于如何避免使用inline-anonymous类声明的综合访问编译器警告,这是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆