Java Tasks don’t do Lambdas

I was spinning a thread recently and it was pointed out to me that the environment I was working in at the time used Task (JavaFX code) for such things. My thread was being created with a Lambda expression as the action to be performed. It surprised me when I could not directly translate that to a Task.

After a bit of research I found this post discussing why that is the case (as a side-effect of the fact that Task is an abstract class). As with so many things in Java where the choice is to accept less expressive and longer winded approaches to limit language level complexity, I’m not sure I agree with the choice, but it is what it is at this point.

Adding in the anonymous local class framing isn’t a big deal and that’s clearly the way to go for this item. 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.