Skip to content

Conversation

@mbruggmann
Copy link
Contributor

@mbruggmann mbruggmann commented Jul 4, 2024

For a method that has a type parameter, we can't replace anonymous class declarations with a lambda. For example:

public interface I {
  <T> List<T> call();
}

// Can't be replaced by lambda
final I i = new I() {
  @Override
  public <T> List<T> call() { ... }
};

The proposed fix is to check the method in question for type parameters, and if there are any, return early from UseLambdaForFunctionalInterface without making any changes.

Fixes #309

@mbruggmann mbruggmann marked this pull request as ready for review July 4, 2024 14:23
Copy link
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for exploring, finding and contributing the fix!

@timtebeek timtebeek added the bug Something isn't working label Jul 4, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • src/main/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiterals.java
    • lines 250-250

@timtebeek timtebeek merged commit fc7ed29 into openrewrite:main Jul 4, 2024
@mbruggmann mbruggmann deleted the dont-use-lambda-with-type-parameter branch July 5, 2024 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

UseLambdaForFunctionalInterface should exclude methods with type paramters

2 participants