Created
November 12, 2018 09:38
-
-
Save kmizu/9e3e12b3c57631f29175b6fadcd72b48 to your computer and use it in GitHub Desktop.
String Switch in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Compiled from "StringSwitch.java" | |
public class StringSwitch { | |
public StringSwitch(); | |
Code: | |
0: aload_0 | |
1: invokespecial #1 // Method java/lang/Object."<init>":()V | |
4: return | |
public static void main(java.lang.String[]); | |
Code: | |
0: ldc #2 // String foo | |
2: astore_1 | |
3: aload_1 | |
4: astore_2 | |
5: iconst_m1 | |
6: istore_3 | |
7: aload_2 | |
8: invokevirtual #3 // Method java/lang/String.hashCode:()I | |
11: lookupswitch { // 3 | |
97299: 58 | |
97307: 72 | |
101574: 44 | |
default: 83 | |
} | |
44: aload_2 | |
45: ldc #2 // String foo | |
47: invokevirtual #4 // Method java/lang/String.equals:(Ljava/lang/Object;)Z | |
50: ifeq 83 | |
53: iconst_0 | |
54: istore_3 | |
55: goto 83 | |
58: aload_2 | |
59: ldc #5 // String bar | |
61: invokevirtual #4 // Method java/lang/String.equals:(Ljava/lang/Object;)Z | |
64: ifeq 83 | |
67: iconst_1 | |
68: istore_3 | |
69: goto 83 | |
72: aload_2 | |
73: ldc #6 // String baz | |
75: invokevirtual #4 // Method java/lang/String.equals:(Ljava/lang/Object;)Z | |
78: ifeq 83 | |
81: iconst_2 | |
82: istore_3 | |
83: iload_3 | |
84: tableswitch { // 0 to 2 | |
0: 112 | |
1: 123 | |
2: 134 | |
default: 142 | |
} | |
112: getstatic #7 // Field java/lang/System.out:Ljava/io/PrintStream; | |
115: ldc #2 // String foo | |
117: invokevirtual #8 // Method java/io/PrintStream.println:(Ljava/lang/String;)V | |
120: goto 142 | |
123: getstatic #7 // Field java/lang/System.out:Ljava/io/PrintStream; | |
126: ldc #2 // String foo | |
128: invokevirtual #8 // Method java/io/PrintStream.println:(Ljava/lang/String;)V | |
131: goto 142 | |
134: getstatic #7 // Field java/lang/System.out:Ljava/io/PrintStream; | |
137: ldc #2 // String foo | |
139: invokevirtual #8 // Method java/io/PrintStream.println:(Ljava/lang/String;)V | |
142: return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StringSwitch { | |
public static void main(String[] args) { | |
String f = "foo"; | |
switch(f) { | |
case "foo": | |
System.out.println("foo"); | |
break; | |
case "bar": | |
System.out.println("foo"); | |
break; | |
case "baz": | |
System.out.println("foo"); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment