在Eclipse下开发Java应用程序时,我收到了关于"通过合成方法访问的方法/值"的警告.解决方案只是将私有访问修饰符更改为默认级别.
这让我想知道:使用合成方法的惩罚是什么?有一些?我假设编译器/ Eclipse会引发警告,但它是如此相关的东西还是可以安全忽略的东西?
我没有在这里看到这些信息,所以我问.
我遇到的一件事是服务类(比如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) 我有以下代码:
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.
谁能准确解释一下
谢谢