是的结果和结果将是相同的。但是对于“代码相同”来说,肯定是“不”。
编辑:就像评论中提到的,这是两个编译版本:
版本 1:
Compiled from "Hello.java"
public class main.java.Hello {
public main.java.Hello();
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 Hello, World!
2: astore_1
3: iconst_0
4: istore_2
5: aload_1
6: invokevirtual #3 // Method java/lang/String.toLowerCase:()Ljava/lang/String;
9: astore_1
10: iconst_0
11: istore_3
12: iload_3
13: aload_1
14: invokevirtual #4 // Method java/lang/String.length:()I
17: if_icmpge 86
20: aload_1
21: iload_3
22: invokevirtual #5 // Method java/lang/String.charAt:(I)C
25: lookupswitch { // 5
97: 76
101: 76
105: 76
111: 76
117: 76
default: 80
}
76: iload_2
77: iconst_1
78: iadd
79: istore_2
80: iinc 3, 1
83: goto 12
86: getstatic #6 // Field java/lang/System.out:Ljava/io/PrintStream;
89: new #7 // class java/lang/StringBuilder
92: dup
93: invokespecial #8 // Method java/lang/StringBuilder."<init>":()V
96: ldc #9 // String Got:
98: invokevirtual #10 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
101: iload_2
102: invokevirtual #11 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
105: invokevirtual #12 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
108: invokevirtual #13 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
111: return
}
版本 2:
Compiled from "Hello.java"
public class main.java.Hello {
public main.java.Hello();
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 Hello, World!
2: astore_1
3: iconst_0
4: istore_2
5: aload_1
6: invokevirtual #3 // Method java/lang/String.toLowerCase:()Ljava/lang/String;
9: astore_1
10: iconst_0
11: istore_3
12: iload_3
13: aload_1
14: invokevirtual #4 // Method java/lang/String.length:()I
17: if_icmpge 114
20: aload_1
21: iload_3
22: invokevirtual #5 // Method java/lang/String.charAt:(I)C
25: lookupswitch { // 5
97: 76
101: 83
105: 90
111: 97
117: 104
default: 108
}
76: iload_2
77: iconst_1
78: iadd
79: istore_2
80: goto 108
83: iload_2
84: iconst_1
85: iadd
86: istore_2
87: goto 108
90: iload_2
91: iconst_1
92: iadd
93: istore_2
94: goto 108
97: iload_2
98: iconst_1
99: iadd
100: istore_2
101: goto 108
104: iload_2
105: iconst_1
106: iadd
107: istore_2
108: iinc 3, 1
111: goto 12
114: getstatic #6 // Field java/lang/System.out:Ljava/io/PrintStream;
117: new #7 // class java/lang/StringBuilder
120: dup
121: invokespecial #8 // Method java/lang/StringBuilder."<init>":()V
124: ldc #9 // String Got:
126: invokevirtual #10 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
129: iload_2
130: invokevirtual #11 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
133: invokevirtual #12 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
136: invokevirtual #13 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
139: return
}
差异 -e ou1 ou2
39,51c
80: goto 108
83: iload_2
84: iconst_1
85: iadd
86: istore_2
87: goto 108
90: iload_2
91: iconst_1
92: iadd
93: istore_2
94: goto 108
97: iload_2
98: iconst_1
99: iadd
100: istore_2
101: goto 108
104: iload_2
105: iconst_1
106: iadd
107: istore_2
108: iinc 3, 1
111: goto 12
114: getstatic #6 // Field java/lang/System.out:Ljava/io/PrintStream;
117: new #7 // class java/lang/StringBuilder
120: dup
121: invokespecial #8 // Method java/lang/StringBuilder."<init>":()V
124: ldc #9 // String Got:
126: invokevirtual #10 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
129: iload_2
130: invokevirtual #11 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
133: invokevirtual #12 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
136: invokevirtual #13 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
139: return
.
29,33c
101: 83
105: 90
111: 97
117: 104
default: 108
.
23c
17: if_icmpge 114