Groovy学习笔记-实现接口

时间:2023-01-16 17:41:14

1.单个委托方法的实现

button.addActionListener(
  { println 'Implement ActionListener' } as ActionListener   
)

2.实现接口中的多个方法:使用映射,以每个方法的名字作为键,以方法对应的代码块作为键值,使用:分割方法名和代码块

handleFocus = [
    focusGained : {msgLabel.setText("Good to see you")},
    focusLost : {msgLabel.setText("Come back soon")}
]

button.addFocusListener(handleFocus as FocusListener)