Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Abstract listeners and lambdas  RSS feed

 
Stephan van Hulst
Saloon Keeper
Posts: 6980
110
  • 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
Saloon Keeper
Posts: 6980
110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess I'll move this to the Swing forum :P
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • 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
Saloon Keeper
Posts: 6980
110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's why the Handlers class returns Action, not ActionListener
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!