相关疑难解决方法(0)

合成方法的惩罚是什么?

在Eclipse下开发Java应用程序时,我收到了关于"通过合成方法访问的方法/值"的警告.解决方案只是将私有访问修饰符更改为默认级别.

这让我想知道:使用合成方法的惩罚是什么?有一些?我假设编译器/ Eclipse会引发警告,但它是如此相关的东西还是可以安全忽略的东西?

我没有在这里看到这些信息,所以我问.

java jvm java-synthetic-methods

16
推荐指数
1
解决办法
2433
查看次数

大型内部类和私有变量

我遇到的一件事是服务类(比如JBoss服务)由于帮助器内部类而变得过大.我还没有找到一个打破课堂的好方法.这些助手通常是线程.这是一个例子:

/** Asset service keeps track of the metadata about assets that live on other
 * systems. Complications include the fact the assets have a lifecycle and their
 * physical representation lives on other systems that have to be polled to find
 * out if the Asset is still there. */
public class AssetService
{
  //...various private variables
  //...various methods

  public AssetService()
  {
    Job pollerJob = jobService.schedule( new AssetPoller() );
    Job lifeCycleJob = jobService.schedule( AssetLifecycleMonitor() );
  }

  class AssetPoller
  { …
Run Code Online (Sandbox Code Playgroud)

java jboss class-design

9
推荐指数
1
解决办法
908
查看次数

如何使用内联匿名类声明避免合成访问编译器警告,这意味着什么?

我有以下代码:

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.

谁能准确解释一下

  1. 这是什么意思,
  2. 如果我保持原样(因为它只是一个警告),可能的后果可能意味着什么,以及
  3. 我该如何解决?

谢谢

java eclipse compiler-warnings java-synthetic-methods

5
推荐指数
1
解决办法
4044
查看次数