import javax.swing.JButton;
import javax.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class foo extends JButton implements ActionListener
{
public foo()
{
super();
addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
bar(e);
}
}
当我按照这些行编译某些内容时,NetBeans会抛出一个小错误:
Leaking in this constructor
或Passing Suspicious Parameter in this constructor
我们应该或不应该使用这样的编码约定?使用匿名类更好吗?
我想知道这个错误的意义。 我从Oracle网站上的Java教程中学到了这种用法。那么,这是一个糟糕的编码实践吗?