Skip to content

Instantly share code, notes, and snippets.

@codebje
Last active October 16, 2016 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codebje/370bff4139be74b1db94fced0e17ad68 to your computer and use it in GitHub Desktop.
Save codebje/370bff4139be74b1db94fced0e17ad68 to your computer and use it in GitHub Desktop.
class Foo {
Foo();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public boolean isEven(java.lang.Integer);
Code:
0: aload_1
1: invokevirtual #2 // Method java/lang/Integer.intValue:()I
4: iconst_2
5: irem
6: ifne 13
9: iconst_1
10: goto 14
13: iconst_0
14: ireturn
public static void main(java.lang.String[]);
Code:
0: new #3 // class Foo
3: dup
4: invokespecial #4 // Method "<init>":()V
7: astore_1
8: getstatic #5 // Field java/lang/System.out:Ljava/io/PrintStream;
11: bipush 6
13: anewarray #6 // class java/lang/Integer
16: dup
17: iconst_0
18: iconst_1
19: invokestatic #7 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
22: aastore
23: dup
24: iconst_1
25: iconst_3
26: invokestatic #7 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
29: aastore
30: dup
31: iconst_2
32: bipush 77
34: invokestatic #7 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
37: aastore
38: dup
39: iconst_3
40: iconst_4
41: invokestatic #7 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
44: aastore
45: dup
46: iconst_4
47: iconst_2
48: invokestatic #7 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
51: aastore
52: dup
53: iconst_5
54: bipush 19
56: invokestatic #7 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
59: aastore
60: invokestatic #8 // InterfaceMethod java/util/stream/Stream.of:([Ljava/lang/Object;)Ljava/util/stream/Stream;
63: aload_1
64: dup
65: invokevirtual #9 // Method java/lang/Object.getClass:()Ljava/lang/Class;
68: pop
69: invokedynamic #10, 0 // InvokeDynamic #0:test:(LFoo;)Ljava/util/function/Predicate;
74: invokeinterface #11, 2 // InterfaceMethod java/util/stream/Stream.filter:(Ljava/util/function/Predicate;)Ljava/util/stream/Stream;
79: invokedynamic #12, 0 // InvokeDynamic #1:applyAsInt:()Ljava/util/function/ToIntFunction;
84: invokeinterface #13, 2 // InterfaceMethod java/util/stream/Stream.mapToInt:(Ljava/util/function/ToIntFunction;)Ljava/util/stream/IntStream;
89: invokeinterface #14, 1 // InterfaceMethod java/util/stream/IntStream.sum:()I
94: invokevirtual #15 // Method java/io/PrintStream.println:(I)V
97: return
}
import java.util.stream.Stream;
class Foo {
public boolean isEven(Integer n) {
return n % 2 == 0;
}
public static void main(String[] args) {
Foo foo = new Foo();
System.out.println(Stream.of(1,3,77,4,2,19)
.filter(foo::isEven)
.mapToInt(n -> n)
.sum());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment