langtools/test/tools/javac/StringsInSwitch/NonConstantLabel.java
author darcy
Mon, 02 Nov 2009 21:36:59 -0800
changeset 4142 bd950c8f4fb3
child 6150 d055fa8ced62
permissions -rw-r--r--
6827009: Project Coin: Strings in Switch Reviewed-by: jjg, mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4142
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
     1
/*
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
     2
 * @test  /nodynamiccopyright/
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
     3
 * @bug 6827009
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
     4
 * @summary Check for non-constant case labels.
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
     5
 * @compile/fail -source 6 NonConstantLabel.java
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
     6
 * @compile/fail/ref=NonConstantLabel.out -XDstdout -XDrawDiagnostics NonConstantLabel.java
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
     7
 */
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
     8
class NonConstantLabel {
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
     9
    String m(String s) {
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
    10
        String fauxConstant = "Goodbye Cruel World";
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
    11
        switch(s) {
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
    12
        case "Hello World":
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
    13
            return(s);
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
    14
        case fauxConstant:
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
    15
            return (s + s);
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
    16
        }
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
    17
    }
bd950c8f4fb3 6827009: Project Coin: Strings in Switch
darcy
parents:
diff changeset
    18
}