mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-02 19:28:23 +07:00
java redundant cast: forbid changing of substitutor if cast is removed (IDEA-184330)
this way neighbour functional expressions can't be broken GitOrigin-RevId: c13823eca79157030f3dde53fa6a6d496be9c2b7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1ad48d35aa
commit
c2ec0c2e78
@@ -0,0 +1,58 @@
|
||||
import java.util.function.*;
|
||||
|
||||
class A {
|
||||
<T> void f(T a, Consumer<T> b) { }
|
||||
|
||||
void g(Object o) {
|
||||
f((String) o, (t) -> t.charAt(0));
|
||||
}
|
||||
}
|
||||
|
||||
class Foo {
|
||||
|
||||
class Base { public int sub; }
|
||||
|
||||
class Sub1 extends Base { }
|
||||
|
||||
class Sub2 extends Base { }
|
||||
|
||||
public <T> void doSomething(T thing, BiConsumer<String, T> action) {
|
||||
action.accept("HELLO", thing);
|
||||
}
|
||||
|
||||
private Sub1 s1;
|
||||
private Sub2 s2;
|
||||
|
||||
public void foo(Base base) {
|
||||
if (base.sub == 1)
|
||||
doSomething((Sub1) base, (s, b) -> { System.out.println(s); this.s1 = b; });
|
||||
if (base.sub == 2)
|
||||
doSomething((Sub2) base, (s, b) -> { System.out.println(s); this.s2 = b; });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class UnnecessaryCastError {
|
||||
|
||||
public static void main(String args[]) {
|
||||
Env<String> env = new Env<>();
|
||||
|
||||
map((String) env.getArgument("to"), x -> parse(x));
|
||||
}
|
||||
|
||||
public static <T, U> U map(T t, Function<T, U> mapper) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String parse(String text) {
|
||||
return null;
|
||||
}
|
||||
|
||||
static class Env<T> {
|
||||
<T> T getArgument(String s) {
|
||||
return (<warning descr="Casting 'null' to 'T' is redundant">T</warning>) null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user