Skip to content

Instantly share code, notes, and snippets.

@kamekoopa
Last active August 29, 2015 13:56
Show Gist options
  • Save kamekoopa/9044874 to your computer and use it in GitHub Desktop.
Save kamekoopa/9044874 to your computer and use it in GitHub Desktop.
finalのやつ
public class Hoge {
public static void main(String[] args) throws Exception {
Hoge hoge = new Hoge();
System.out.println(hoge.doHoge());
return;
}
public int doHoge(){
final int a = 1;
final int b = 1;
return a + b;
}
}
Compiled from "Hoge.java"
public class Hoge {
public Hoge();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]) throws java.lang.Exception;
Code:
0: new #2 // class Hoge
3: dup
4: invokespecial #3 // Method "<init>":()V
7: astore_1
8: getstatic #4 // Field java/lang/System.out:Ljava/io/PrintStream;
11: aload_1
12: invokevirtual #5 // Method doHoge:()I
15: invokevirtual #6 // Method java/io/PrintStream.println:(I)V
18: return
public int doHoge();
Code:
0: iconst_2
1: ireturn
}
public class Hugo {
public static void main(String[] args) throws Exception {
Hugo hugo = new Hugo();
System.out.println(hugo.doHugo());
return;
}
public int doHugo(){
int a = 1;
int b = 1;
return a + b;
}
}
Compiled from "Hugo.java"
public class Hugo {
public Hugo();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]) throws java.lang.Exception;
Code:
0: new #2 // class Hugo
3: dup
4: invokespecial #3 // Method "<init>":()V
7: astore_1
8: getstatic #4 // Field java/lang/System.out:Ljava/io/PrintStream;
11: aload_1
12: invokevirtual #5 // Method doHugo:()I
15: invokevirtual #6 // Method java/io/PrintStream.println:(I)V
18: return
public int doHugo();
Code:
0: iconst_1
1: istore_1
2: iconst_1
3: istore_2
4: iload_1
5: iload_2
6: iadd
7: ireturn
}
public class Final {
public static void main(String[] args) {
final int NUM = 31;
for (int i = 0; i < Integer.MAX_VALUE; i++) {
int hash = 17;
hash = hash * NUM + i;
hash = hash * NUM + i;
hash = hash * NUM + i;
hash = hash * NUM + i;
hash = hash * NUM + i;
}
}
}
Compiled from "Final.java"
public class Final {
public Final();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: iconst_0
1: istore_2
2: iload_2
3: ldc #2 // int 2147483647
5: if_icmpge 52
8: bipush 17
10: istore_3
11: iload_3
12: bipush 31
14: imul
15: iload_2
16: iadd
17: istore_3
18: iload_3
19: bipush 31
21: imul
22: iload_2
23: iadd
24: istore_3
25: iload_3
26: bipush 31
28: imul
29: iload_2
30: iadd
31: istore_3
32: iload_3
33: bipush 31
35: imul
36: iload_2
37: iadd
38: istore_3
39: iload_3
40: bipush 31
42: imul
43: iload_2
44: iadd
45: istore_3
46: iinc 2, 1
49: goto 2
52: return
}
public class NotFinal {
public static void main(String[] args) {
int NUM = 31;
for (int i = 0; i < Integer.MAX_VALUE; i++) {
int hash = 17;
hash = hash * NUM + i;
hash = hash * NUM + i;
hash = hash * NUM + i;
hash = hash * NUM + i;
hash = hash * NUM + i;
}
}
}
Compiled from "NotFinal.java"
public class NotFinal {
public NotFinal();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: bipush 31
2: istore_1
3: iconst_0
4: istore_2
5: iload_2
6: ldc #2 // int 2147483647
8: if_icmpge 50
11: bipush 17
13: istore_3
14: iload_3
15: iload_1
16: imul
17: iload_2
18: iadd
19: istore_3
20: iload_3
21: iload_1
22: imul
23: iload_2
24: iadd
25: istore_3
26: iload_3
27: iload_1
28: imul
29: iload_2
30: iadd
31: istore_3
32: iload_3
33: iload_1
34: imul
35: iload_2
36: iadd
37: istore_3
38: iload_3
39: iload_1
40: imul
41: iload_2
42: iadd
43: istore_3
44: iinc 2, 1
47: goto 5
50: return
}
@kamekoopa
Copy link
Author

ループごとにじゃない、演算ごとにだ。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment