我在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
的访问修饰符。同时也不想为它创建一个getter。
应该做出什么样的改变?
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");
}
}
使用**
的行会给我相同的警告。