-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Lambdas to be passed as item processors in Java DSL #4061
Comments
The milestone release 5.0.0-M2 is due shortly and, up to now, this issue has not sparked the interest that I expected. Is the proposal too aggressive? An alternative is to now declare the possibility to use a In my opinion, this issue should really not be deferred to Spring Batch 6. Assuming that the release cadences of the Java ecosystem stay constant, this would lead to a situation where Spring Batch offers idiomatic support for a Java 8 feature (i.e. lambdas) only after the release of Java 29. |
Still trying to summon support for this one! 😄 At least two past issues support my case: #3749 and #3880. Both problem descriptions contain a cast lambda being passed to In my opinion, these separate code paths make the step DSL unnecessarily hard to reason about. And as elaborated in the original post, I don't see that the code path for |
I agree that the cast is verbose and that this issue should not be deferred to v6.
For consistency, we typically follow the same policy as Spring Boot for deprecations. This means if we deprecate the overloaded method in v5.0, we would only remove it in v5.2, not in v5.1. It is always aggressive to remove a public API without deprecation, but I think we can make the exception in a major version like v5, especially that the migration approach you suggested is straight-forward. That said and based on the current yearly-based release cadence of Spring Batch for minor versions, I see no need to keep this overloaded method (and afflict the ceremonial cast to our users) for at least two years from v5 GA date, so I will plan #4062 for 5.0.0-M3. However, I disagree on the removal of |
@benas Thanks! That's great news. I've reverted the removal of the |
Status quo in Spring Batch 4.x
In Spring Batch 4.x, it is not possible to pass a lambda or method reference to
SimpleStepBuilder::processor
.The method is overloaded to accept either an
ItemProcessor
or aFunction
, which both qualify as functional interfaces. This makes passing a lambda ambivalent if it is not explicitly cast to one of the two. In my opinion, the casts that need to be applied to pass lambdas are unnecessarily ceremonial and feel clunky in modern Java that strongly favors lambdas over explicitFunction
.In other words, it would be great if one could write
instead of either
or
Feature request for Spring Batch 5.0
To allow lambdas and method references to be passed directly to
SimpleStepBuilder::processor
, please consider to drop the possibility to passFunction
. If the method only acceptedItemProcessor
, passing a lambda would not be ambivalent and not require a cast.This is a breaking change in a central DSL but I think Spring Batch 5.0 is the perfect moment to do this.
From my perspective, most applications would need to simply drop casts to
Function
to migrate from 4.x to 5.0. Applications that do use actualFunction
objects as arguments forSimpleStepBuilder::processor
would need to replace code likewith
for a straight-forward migration approach.
The text was updated successfully, but these errors were encountered: