[java-inspection] IDEA-252155 False positive "Lambda can be replaced with method reference" when casting with additional bounds

GitOrigin-RevId: 2b752e6b47a0d53b05b4e7cd98064c5ce54e2904
This commit is contained in:
Tagir Valeev
2020-10-06 14:18:26 +07:00
committed by intellij-monorepo-bot
parent 7e453a814d
commit d833da5281
2 changed files with 9 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
// "Replace lambda with method reference" "false"
import java.util.function.Function;
class Bar extends Random {
public void test(Object obj) {
Function<Object, Object> fn = s -> (Cloneable & Serializable)<caret>s;
}
}

View File

@@ -280,6 +280,7 @@ public class LambdaCanBeMethodReferenceInspection extends AbstractBaseJavaLocalI
}
PsiType type = typeElement.getType();
if (type instanceof PsiPrimitiveType || PsiUtil.resolveClassInType(type) instanceof PsiTypeParameter) return null;
if (type instanceof PsiIntersectionType) return null;
return new MethodReferenceCandidate(expression, true, javaSettings.REPLACE_INSTANCEOF_AND_CAST);
}
}