• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Abstract listeners and lambdas

 
Saloon Keeper
Posts: 15554
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 15554
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess I'll move this to the Swing forum :P
 
Marshal
Posts: 79263
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 15554
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's why the Handlers class returns Action, not ActionListener
 
reply
    Bookmark Topic Watch Topic
  • New Topic