关于匿名内部类构造器参数传递的问题
书上有句话说:由于匿名内部类不能有构造器,所以将匿名内部类构造器参数传递给父类构造器。这句话怎么理解?
------解决方案--------------------
匿名内部类的形式:
1 new SuperClass(){...}
2 new SuperClass(...){...}
3 new SuperClass(){{...}}
4 new Interface(){...}
这里说的应该是第二种
举个例子
Action openAction = new javax.swing.AbstractAction("Open"){
public void actionPerformed(ActionEvent e){
...
}
};
1
addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){...}
});
3
Map mmm = new HashMap(){{ put("One",1); put("Two",2);}};
4
addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){...}
});