Java接口可以有构造函数吗?

Eri*_*ton 0 java interface

ActionListener是一个接口,但为什么我可以创建实例对象?

   JButton button = new JButton("Button1");

   ActionListener me = new ActionListener(){
        public void actionPerformed(ActionEvent ae){
            JOptionPane.showMessageDialog(null,ae.getActionCommand());  
        }
    };
    button.addActionListener(me);
Run Code Online (Sandbox Code Playgroud)

还有什么?我不确定.请帮我.

Joa*_*uer 6

你在这里看到的被称为匿名类:me将被分配一个实现ActionListener接口的匿名(未命名)类的实例.