Skip to content

Conversation

@behappyleee
Copy link

@behappyleee behappyleee commented Nov 15, 2025

Summary

Add the @FunctionalInterface annotation to Transformer.

Details

Transformer already has a single abstract method, so marking it as a functional interface clarifies its intended use and provides better compile-time checks and IDE support.

Compatibility

No behavior changes; fully backward-compatible.

Signed-off-by: behappyleee <72903623+behappyleee@users.noreply.github.com>
@behappyleee behappyleee force-pushed the fix-functional-annotation-transformer-interface branch from 0dabdf6 to f3d90b3 Compare November 15, 2025 15:20
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 15, 2025
@bclozel
Copy link
Member

bclozel commented Nov 16, 2025

@behappyleee do you have a particular use case needing this change? Can you share a code snippet of what you are trying to achieve?

I am asking because this code is being shaded in spring and only apply strictly necessary patches there.

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Nov 16, 2025
@behappyleee
Copy link
Author

behappyleee commented Nov 16, 2025

@behappyleee do you have a particular use case needing this change? Can you share a code snippet of what you are trying to achieve?

I am asking because this code is being shaded in spring and only apply strictly necessary patches there.

@bclozel
Hi, thanks for checking this!

The reason I applied this change is that I wanted to use Transformer as a functional interface in a small utility module, mainly for passing lambda expressions.
Without the @FunctionalInterface annotation, the interface works, but the annotation helps enforce its intended usage and prevents accidental method additions during local development.

Nothing beyond this is required on Spring’s side, and there’s no need for any additional patches in the shaded code.
My change was only for my own usage outside of Spring’s internal shading logic.

If this causes any concern, feel free to point it out — I can adjust my approach accordingly.

Here’s a small snippet showing how I intended to use the Transformer interface as a functional interface:

Transformer trimTransformer = value -> {
    if (value instanceof String s) {
        return s.trim();
    }
    return value;
};

Object result = trimTransformer.transform("hello  ");

Thanks again for the clarification!

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 16, 2025
@bclozel
Copy link
Member

bclozel commented Nov 17, 2025

@jhoeller do you think it's worth applying this change to our cglib fork? It's adding maintenance cost so we must consider the tradeoffs here.

@bclozel bclozel added status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Nov 17, 2025
@sbrannen sbrannen changed the title refactor: annotate Transformer Interface with @FunctionalInterface Annotate CGLIB Transformer interface with @FunctionalInterface Nov 17, 2025
@sbrannen
Copy link
Member

sbrannen commented Nov 17, 2025

Here’s a small snippet showing how I intended to use the Transformer interface as a functional interface:

Transformer trimTransformer = value -> {
    if (value instanceof String s) {
        return s.trim();
    }
    return value;
};

Object result = trimTransformer.transform("hello  ");

In that example, it appears that you are using Transformer without using anything else from CGLIB.

Whereas, as far as I know, Transformer is only intended to be used with the transform(Collection, Transformer) and bucket(Collection, Transformer) methods in org.springframework.cglib.core.CollectionUtils.

And I don't consider that to be a supported use case with Spring's fork of CGLIB.

Instead, if you want to use something like Transformer I would recommend the use of standard functional interfaces like java.util.function.Function<T, R>. Or if you use Apache Commons Collections, you could use org.apache.commons.collections4.Transformer<I, O>.

In summary, I don't see any value in annotating org.springframework.cglib.core.Transformer with @FunctionalInterface.

@sbrannen
Copy link
Member

Closing due to the rationale provided in #35823 (comment).

@sbrannen sbrannen closed this Nov 17, 2025
@sbrannen sbrannen self-assigned this Nov 17, 2025
@sbrannen sbrannen added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team labels Nov 17, 2025
@behappyleee
Copy link
Author

Thank you for the clarification and for pointing me in the right direction. I appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants