mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 03:13:40 +07:00
IDEA-111450 false positive for "Redundant type cast" inspection
This commit is contained in:
committed by
Anna Kozlova
parent
b816d2770e
commit
fbc3d18f9e
+38
@@ -0,0 +1,38 @@
|
||||
import java.lang.Character;
|
||||
import java.util.List;
|
||||
|
||||
public class Test {
|
||||
public static void test() {
|
||||
Character c1 = '1';
|
||||
Character c2 = '2';
|
||||
Object o = '3';
|
||||
|
||||
// A cast on either operand is required to force a primitive comparison; not redundant.
|
||||
System.out.println((char) c1 == c2);
|
||||
System.out.println(c1 == (char) c2);
|
||||
|
||||
// If one operand is a primitive, and the other is a wrapper, the wrapper need not be cast.
|
||||
System.out.println((<warning descr="Casting 'c1' to 'char' is redundant">char</warning>) c1 == '*');
|
||||
System.out.println('*' == (<warning descr="Casting 'c1' to 'char' is redundant">char</warning>) c1);
|
||||
|
||||
// The cast on the Object is required to force a primitive comparison; not redundant.
|
||||
System.out.println((char) o == '*');
|
||||
System.out.println('*' == (char) o);
|
||||
|
||||
// The cast on the Object is required to force a primitive comparison; not redundant.
|
||||
System.out.println((Character) o == '*');
|
||||
System.out.println('*' == (Character) o);
|
||||
|
||||
// The cast on the Object triggers an implicit unboxing of the wrapper; not redundant.
|
||||
System.out.println((char) o == c1);
|
||||
System.out.println(c1 == (char) o);
|
||||
|
||||
// A cast on the Object is required for a primitive comparison, but the wrapper cast is redundant.
|
||||
System.out.println((char) o == (<warning descr="Casting 'c1' to 'char' is redundant">char</warning>) c1);
|
||||
System.out.println((<warning descr="Casting 'c1' to 'char' is redundant">char</warning>) c1 == (char) o);
|
||||
|
||||
// Although a reference comparison, the cast on the wrapper has a side effect; not redundant.
|
||||
System.out.println(o == (char) c1);
|
||||
System.out.println((char) c1 == o);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user