Skip to content

ResolvableType should support resolving lambda types [SPR-13698] #18273

Closed

Description

@spring-projects-issues

Oliver Drotbohm opened SPR-13698 and commented

This test case currently fails:

Function<Long, String> toString = value -> value.toString();

ResolvableType type = ResolvableType.forClass(Function.class, toString.getClass());

assertThat(type.getGeneric(0).getRawClass(), is(typeCompatibleWith(Long.class)));
assertThat(type.getGeneric(1).getRawClass(), is(typeCompatibleWith(String.class)));

This helper library (itself inspired by Spring's GenericTypeResolver) seems to use an additional code path to use API introduced in Java 8 to resolve lambdas in a special way.


Issue Links:

Activity

  1. spring-projects-issues commented on Nov 18, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    I thought we had already such report (with a lengthy discussion with thomas.darimont) but I can't find it anymore

  2. spring-projects-issues commented on Nov 23, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Indeed, we rejected in back then since the "API introduced in Java 8" is actually internal (sun.reflect.ConstantPool), and the entire approach is rather hacky, even relying on the index of entries in the constant pool... This is very likely to break on JDK 9 eventually, so I'm reluctant to add support for it at this point.

    Juergen

  3. spring-projects-issues commented on Nov 23, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Oliver Drotbohm commented

    Maybe we should bring this up with the JDK team then, they might be able to fix this? I haven't looked deeply into the code but is there a particular reason the standard lookup algorithm doesn't work here? I just think it's kind of weird to see a lambda failing while the very same declaration works if you create the anonymous class. It basically subverts our "use Java 8 and everything will be better" message to some degree.

  4. spring-projects-issues commented on Dec 18, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Oliver Drotbohm commented

    I just ran into this again with code that was expecting a Converter and I thought I could just hand in a lambda, which I couldn't as the called code was inspecting the given instance for generic types. I think that's the main issue with this one: for a user it's not at all obvious whether you can use a lambda with a SAM type or not.

  5. added
    status: waiting-for-triage
    type: enhancement
    in: core
    and removed
    type: enhancement
    on Jan 11, 2019
  6. added
    status: bulk-closed
    and removed
    status: waiting-for-triage
    on Jan 11, 2019
  7. spring-projects-issues commented on Jan 12, 2019

    @spring-projects-issues
    CollaboratorAuthor

    Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: corestatus: bulk-closed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions