-
Notifications
You must be signed in to change notification settings - Fork 44
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
UseLambdaForFunctionalInterface should exclude methods with type paramters #309
Comments
Thanks for the runnable example @mbruggmann ; I've had a brief look locally with these minor changes to your test. @Test
@Issue("https://github.com/openrewrite/rewrite-static-analysis/issues/309")
void dontUseLambdaForMethodWithTypeParameter() {
//language=java
rewriteRun(
spec -> spec.parser(JavaParser.fromJavaVersion().dependsOn(
"""
package com.helloworld;
import java.util.List;
public interface I {
<T> List<T> call();
}
"""
)),
java(
// can't transform to lambda because of the type argument of I#call()
"""
package com.helloworld;
import java.util.List;
class Hello {
public void hello() {
final I i = new I() {
@Override
public <T> List<T> call() {
return null;
}
};
final List<String> list = i.call();
}
}
"""
)
);
} Did you already explore any potential fixes for this recipe? |
I've pushed up the above test to 045bd00 if you want to have a look. Earlier we had handled another case differently by introducing casting; perhaps good to compare: |
Thanks @timtebeek! |
See the re-enabled testcase. Fixes openrewrite#309
We are using OpenRewrite v8.28.1 and rewrite-static-analysis v1.10.1.
In our codebase, we have an interface with a single method using a type parameter. Something like this:
Which is then implemented in other places using an anonymous class like so:
The
UseLambdaForFunctionalInterface
recipe replaces such inline definitions ofI
with a lambda (final I i = () -> ...;
). That will not compile because of the type argument being lost. I would expect the recipe to bail out and not introduce a lambda in this case.I can reproduce it using this testcase:
The text was updated successfully, but these errors were encountered: