File: ConstantsInterning.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,104 kB
  • sloc: java: 145,916; xml: 839; sh: 518; makefile: 404; perl: 26
file content (36 lines) | stat: -rw-r--r-- 907 bytes parent folder | download | duplicates (3)
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
import org.checkerframework.checker.interning.qual.Interned;

public class ConstantsInterning {

    // All but D should be inferred to be @Interned String.
    final String A = "A";
    final String B = "B";
    final String AB = A + B;
    final String AC = A + "C";
    final String D = new String("D");
    final @Interned String E = new String("E").intern();
    final Object F = "F";

    void foo() {
        @Interned String is;
        is = A;
        is = B;
        is = AB;
        is = A + B;
        is = AC;
        is = A + "C";
        is = A + B + "C";
        // :: error: (assignment.type.incompatible)
        is = D;
        // :: error: (assignment.type.incompatible)
        is = A + E;
        // :: error: (assignment.type.incompatible)
        is = is + is;
        is = Constants2.E;
        is = (String) F;
    }
}

class Constants2 {
    public static final String E = "e";
}