Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/IDEA111450.java
Bas Leijdekkers e72529cff2 capitalize "Java" (IJPF-CR-5078)
GitOrigin-RevId: 124bec7c8071720cc53d7279bfe27f00324f066d
2022-03-31 12:25:27 +00:00

38 lines
1.9 KiB
Java

import java.lang.Character;
import java.util.List;
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 <warning descr="Comparison between Object and primitive is illegal and is accepted in Java 7 only">==</warning> (char) c1);
System.out.println((char) c1 <warning descr="Comparison between Object and primitive is illegal and is accepted in Java 7 only">==</warning> o);
}
}