综合访问器方法警告
我在 eclipse 中做了一些新的警告设置。有了这些新设置,我面临着一个奇怪的警告。阅读后,我知道它是什么,但找不到删除它的方法。
这是我对示例代码的问题
public class Test {
private String testString;
public void performAction() {
new Thread( new Runnable() {
@Override
public void run() {
testString = "initialize"; // **
}
});
}
}
带有**的行在日食中给我一个警告
Read access to enclosing field Test.testString is emulated by a synthetic accessor method.
Increasing its visibility will improve your performance.
问题是,我不想更改 的访问修饰符。另外,不想为它创建一个getter。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");
}
}
行与给了我同样的警告。**