Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Compiled from "MyInterface.java"
public interface batik.MyInterface {
public abstract java.util.List<java.lang.String> strings();
public int totalLength(); // OBSERVERA DEFAULT METHOD I INTERFACE
Code:
0: iconst_0
1: istore_1
2: aload_0
3: invokeinterface #1, 1 // InterfaceMethod strings:()Ljava/util/List;
8: invokeinterface #2, 1 // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
13: astore_2
14: aload_2
15: invokeinterface #3, 1 // InterfaceMethod java/util/Iterator.hasNext:()Z
20: ifeq 43
23: aload_2
24: invokeinterface #4, 1 // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
29: checkcast #5 // class java/lang/String
32: astore_3
33: iload_1
34: aload_3
35: invokevirtual #6 // Method java/lang/String.length:()I
38: iadd
39: istore_1
40: goto 14
43: iload_1
44: ireturn
}
Compiled from "MyClass.java"
public class batik.MyClass implements batik.MyInterface {
public batik.MyClass();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public java.util.List<java.lang.String> strings();
Code:
0: iconst_3
1: anewarray #2 // class java/lang/String
4: dup
5: iconst_0
6: ldc #3 // String 1
8: aastore
9: dup
10: iconst_1
11: ldc #4 // String 22
13: aastore
14: dup
15: iconst_2
16: ldc #5 // String 333
18: aastore
19: invokestatic #6 // Method java/util/Arrays.asList:([Ljava/lang/Object;)Ljava/util/List;
22: areturn
}
AFTER REWRITE=======>
public interface batik.MyInterface { // ======== PURE ABSTRACT INTERFACE =========
public abstract java.util.List<java.lang.String> strings();
public abstract int totalLength();
}
Compiled from "MyClass.java"
public class batik.MyClass implements batik.MyInterface {
public batik.MyClass();
Code:
0: aload_0
1: invokespecial #11 // Method java/lang/Object."<init>":()V
4: return
public java.util.List<java.lang.String> strings();
Code:
0: iconst_3
1: anewarray #15 // class java/lang/String
4: dup
5: iconst_0
6: ldc #17 // String 1
8: aastore
9: dup
10: iconst_1
11: ldc #19 // String 22
13: aastore
14: dup
15: iconst_2
16: ldc #21 // String 333
18: aastore
19: invokestatic #27 // Method java/util/Arrays.asList:([Ljava/lang/Object;)Ljava/util/List;
22: areturn
public int totalLength(); // ===== FORMER DEFAULT METHOD DELEGATES TO STATIC HELPER METHOD ======
Code:
0: aload_0
1: invokestatic #34 // Method batik/MyInterfacehelper.totalLength:(Lbatik/MyInterface;)I
4: ireturn
}
Compiled from "Hello.java"
public class batik.MyInterfacehelper {
private batik.MyInterfacehelper();
Code:
0: aload_0
1: invokespecial #9 // Method java/lang/Object."<init>":()V
4: return
public static int totalLength(batik.MyInterface); // ======= HELPER METHOD =======
Code:
0: iconst_0
1: istore_1
2: aload_0
3: invokeinterface #17, 1 // InterfaceMethod batik/MyInterface.strings:()Ljava/util/List;
8: invokeinterface #23, 1 // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
13: astore_2
14: aload_2
15: invokeinterface #29, 1 // InterfaceMethod java/util/Iterator.hasNext:()Z
20: ifeq 43
23: aload_2
24: invokeinterface #33, 1 // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
29: checkcast #35 // class java/lang/String
32: astore_3
33: iload_1
34: aload_3
35: invokevirtual #39 // Method java/lang/String.length:()I
38: iadd
39: istore_1
40: goto 14
43: iload_1
44: ireturn
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.