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

local lambda and resolveRawArguments returns previous defined local variable class #16

Closed
mickare opened this issue Dec 31, 2015 · 1 comment

Comments

@mickare
Copy link

mickare commented Dec 31, 2015

Java version: Oracle 1.8.0_45

Test-Code:

  @Test
  public void testLambdaFunctionVariableInMethod() {

    final AtomicInteger a = new AtomicInteger(0);
    Function<String, Integer> func = (s) -> {
      a.incrementAndGet();
      return s.hashCode();
    };

    assertArrayEquals(new Class<?>[] {String.class, Integer.class}, TypeResolver.resolveRawArguments(Function.class, func.getClass()));

  }

Fails with:
arrays first differed at element [0]; expected:<class java.lang.String> but was:<class java.util.concurrent.atomic.AtomicInteger>


The Test-Code using a final AtomicInteger in the test object is successfull:

  private final AtomicInteger b = new AtomicInteger(0);

  @Test
  public void testLambdaFunctionVariableInObject() {

    Function<String, Integer> func = (s) -> {
      b.incrementAndGet();
      return s.hashCode();
    };

    assertArrayEquals(new Class<?>[] {String.class, Integer.class}, TypeResolver.resolveRawArguments(Function.class, func.getClass()));

  }
@mickare
Copy link
Author

mickare commented Jan 7, 2016

Could this commit over at the springframework's git solve the issue?
Avoid mismatch between cached top-level versus nested parameter type
spring-projects/spring-framework@c909789

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

No branches or pull requests

2 participants