【发布时间】:2011-05-28 22:19:20
【问题描述】:
我在 eclipse 中做了一些新的警告设置。有了这些新设置,我面临着一个奇怪的警告。阅读后我知道它是什么但找不到删除它的方法。
这是我对示例代码的问题
public class Test {
private String testString;
public void performAction() {
new Thread( new Runnable() {
@Override
public void run() {
testString = "initialize"; // **
}
});
}
}
带有 ** 的行在 eclipse 中给了我一个警告
Read access to enclosing field Test.testString is emulated by a synthetic accessor method.
Increasing its visibility will improve your performance.
问题是,我不想更改testString 的访问修饰符。
另外,不要为它创建一个吸气剂。
应该做哪些改变?
More descriptive example
public class Synthetic
{
private JButton testButton;
public Synthetic()
{
testButton = new JButton("Run");
testButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae)
{
/* Sample code */
if( testButton.getText().equals("Pause") ) {
resetButton(); // **
} else if( testButton.getText().equals("Run") ) {
testButton.setText("Pause"); // **
}
}
}
);
}
public void reset() {
//Some operations
resetButton();
}
private void resetButton() {
testButton.setText("Run");
}
}
** 的行给了我同样的警告。
【问题讨论】:
-
在网站上搜索,有很多关于这个警告的帖子。
标签: java eclipse performance java-synthetic-methods