Skip to content
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

Generics support improvement for core.convert.support.GenericConversionService [SPR-12948] #17541

Closed
spring-projects-issues opened this issue Apr 22, 2015 · 4 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Byron Ellacott opened SPR-12948 and commented

The type signature for addConverter would be more convenient for Java 8 lambda syntax sugar if the types were connected:

public <S, T> void addConverter(Class<S> sourceType, Class<T> targetType, Converter<S, T> converter) {

This would allow, eg:

        import java.time.Period;

        foo.addConverter(String.class, Period.class, Period::parse)

The current signature means the type of the third argument cannot be inferred by the compiler, so lambdas must be explicit:

foo.addConverter(String.class, Period.class, (String s) -> Period.parse(s));

Note that even in this form, the lambda argument must be explicitly typed.


Reference URL: https://github.com/spring-projects/spring-framework/blob/master/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java#L106

Referenced from: commits 8a69159

@spring-projects-issues
Copy link
Collaborator Author

Gary Russell commented

Moving to Spring Framework.

Can you explain why you raised this against Spring Integration?

I just want to be sure there is no misleading information anywhere that drove you to open this against the wrong project.

@spring-projects-issues
Copy link
Collaborator Author

Artem Bilan commented

Byron Ellacott, thank you for pointing that out!

I find this type of improvement as valid one and enough simple.
And yes, it really will help to make that Lambda generics for development time from IDE.
At runtime the ConverterAdapter doesn't take care about generics from provided Converter and just relies on those Class<?> arguments.

No need to worry that we won't have generics in the Lambda in this case!

@spring-projects-issues
Copy link
Collaborator Author

Byron Ellacott commented

Gary,

I thought I had put this against Framework, so pebkac on my part there. Sorry!

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Rolled into 4.3 now. Custom ConverterRegistry implementations might have to adapt their implementation signature at the source level; the change should be binary compatible in an case.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants