Possible Duplicate:
“this” reference escaping during construction?
我想知道是否在构造函数问题中泄漏了此值,因为我认为构造函数必须调用setJMenuBar()方法来完成其构造,所以这是类实现:
public class StaffManagerMainWindow extends JFrame implements ActionListener {
public StaffManagerMainWindow(String title, Image icon) throws HeadlessException {
...
setJMenuBar();
}
private void setJMenuBar() {
...
exitItem.addActionListener(this);
...
}
@Override
public void actionPerformed(ActionEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
最佳答案
我认为构造函数中存在泄漏。您要在对象完全初始化之前传递“ this”。