Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@behappyleee
Copy link

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.

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants