内部类和外部类的关系思考

阅读更多

编译期报错的代码 :

import ipad.IpadHttpUtils;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import utils.StringUtil;
import view.handler.HandlerClass;

public class SendButton extends JButton
{
    private static final long serialVersionUID = 1L;
    
    public SendButton(HandlerClass handler)//没有带final
    {
        super("发送数据");
        this.addActionListener(new ActionListener()
        {
            
            @Override
            public void actionPerformed(ActionEvent e)
            {
                String msg = IpadHttpUtils.post(handler.getParameter(), "authenticate");
                handler.getMessage().setText(StringUtil.showXML(msg));
            }
            
        });
    }
}

 编译期不报错的代码 :

import ipad.IpadHttpUtils;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import utils.StringUtil;
import view.handler.HandlerClass;

public class SendButton extends JButton
{
    private static final long serialVersionUID = 1L;
    
    public SendButton(  final HandlerClass handler)
    {
        super("发送数据");
        this.addActionListener(new ActionListener()
        {
            
            @Override
            public void actionPerformed(ActionEvent e)
            {
                String msg = IpadHttpUtils.post(handler.getParameter(), "authenticate");
                handler.getMessage().setText(StringUtil.showXML(msg));
            }
            
        });
    }
}

 疑惑中,为什么?

你可能感兴趣的:(Swing,Java)