1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
import org.checkerframework.checker.interning.qual.Interned;
public class Comparison {
void testInterned() {
@Interned String a = "foo";
@Interned String b = "bar";
if (a == b) {
System.out.println("yes");
} else {
System.out.println("no");
}
if (a != b) {
System.out.println("no");
} else {
System.out.println("yes");
}
}
void testNotInterned() {
String c = new String("foo");
String d = new String("bar");
// :: error: (not.interned)
if (c == d) {
System.out.println("yes");
} else {
System.out.println("no");
}
// :: error: (not.interned)
if (c != d) {
System.out.println("no");
} else {
System.out.println("yes");
}
}
}
|