[java-inspections] IDEA-328239 Casting with conjunction

- Check if SAM is implemented in conjunction
- Created lambda Methods signature with generic from types

GitOrigin-RevId: 97e21dbacccd9382e48387295a911b127882e625
This commit is contained in:
Mikhail Pyltsin
2023-08-29 18:57:55 +00:00
committed by intellij-monorepo-bot
parent 72ae750abd
commit 3072396ff6
3 changed files with 103 additions and 10 deletions
@@ -5,4 +5,41 @@ class Test {
public static <K extends Comparable<? super K>, V> Comparator<Map.Entry<K, V>> foo() {
return (Comparator<Map.Entry<K, V>> & Serializable)(c1, c2) -> c1.getKey().compareTo(c2.getKey());
}
public static void main(String... args) {
var shouldCompile = (Consumer<Integer> & IntConsumerAdapter1)
i -> System.out.println("Cons3uming dd" + i);
System.out.println(shouldCompile.getClass());
shouldCompile.accept(42);
shouldCompile.accept(Integer.valueOf(52));
var shouldNotCompile = (Consumer<Integer> & IntConsumerAdapter2)
<error descr="No target method found">i -> System.out.println("Consumins2gs " + i)</error>;
shouldNotCompile.accept(42);
shouldNotCompile.accept(Integer.valueOf(52));
}
public interface Consumer<T> {
void accept(T t);
}
public interface IntConsumer {
void accept(int value);
}
@FunctionalInterface
interface IntConsumerAdapter1 extends IntConsumer, Consumer<Integer> {
default void accept(int value) {
accept(Integer.valueOf(value));
}
}
interface IntConsumerAdapter2 extends IntConsumer, Consumer<Integer> {
default void accept(int value) {
accept(Integer.valueOf(value));
}
default void accept(Integer integer) {
}
}
}