开发者社区 问答 正文

关于this 以及接口的问题java 安卓

myButton.addActionListener(this); 
 myFrame.addMouseMotionListener(this); 
 myFrame.addMouseListener(this); 
 myFrame.addWindowListener(this); 
 myButton.addActionListener(this); 
 myFrame.addMouseMotionListener(this); 
 myFrame.addMouseListener(this); 

我说的是这种形式的,这些方法仅仅是想要调用当前类的从接口那里得来的方法(在这个类中已经实现了)为什么不是this.方法名称?而是单独一个this?

展开
收起
爵霸 2016-03-20 11:08:18 1684 分享 版权
1 条回答
写回答
取消 提交回答
  • 为什么不是this. 因为这个方法是要传入一个实现了该接口的一个类的对象。而this.是传入一个方法当然就不行了。这是面相对象多态的知识

    2019-07-17 19:09:09
    赞同 展开评论