• Post Reply Bookmark Topic Watch Topic
  • New Topic

Abstract listeners and lambdas

 
Stephan van Hulst
Bartender
Posts: 6583
84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While working on some Swing code the other day, I got frustrated with all the boilerplate I had to write to add anonymous Action instances to my UI:

Instead, I just wanted to assign a lambda or something. I always have the same problem when I want to add an anonymous Adapter class, such as WindowAdapter, because you can't use lambdas to implement them.

I wrote a helper class to get around this problem, and I thought maybe this pattern would be useful for other people.



Thoughts and comment welcome!
 
Stephan van Hulst
Bartender
Posts: 6583
84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess I'll move this to the Swing forum :P
 
Campbell Ritchie
Marshal
Posts: 52587
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actions have the advantage over listener interfaces that they can support other info over and above the method to be executed, Apart from that go for λs whenever possible, I think.
 
Stephan van Hulst
Bartender
Posts: 6583
84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's why the Handlers class returns Action, not ActionListener
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!