I'm compiling this very simple and naive Java code with Eclipse, and javac:
package anypackagename;
public class Foo {
public static void bar(Class<?> cls) {
while (cls != null) {
final Class<?>[] interfaces = cls.getInterfaces();
// ...
cls = cls.getSuperclass();
}
}
}
The issue is that I'm getting different bytecode with different tools.
Compiled with Eclipse I got:
public static void bar(java.lang.Class<?>);
Code:
0: goto 13
3: aload_0
4: invokevirtual #18 // Method java/lang/Class.getInterfaces:()[Ljava/lang/Class;
7: astore_1
8: aload_0
9: invokevirtual #24 // Method java/lang/Class.getSuperclass:()Ljava/lang/Class;
12: astore_0
13: aload_0
14: ifnonnull 3
17: return
LineNumberTable:
line 6: 0
line 7: 3
line 11: 8
line 6: 13
line 13: 17
however, compiled with javac I got:
public static void bar(java.lang.Class<?>);
Code:
0: aload_0
1: ifnull 17
4: aload_0
5: invokevirtual #2 // Method java/lang/Class.getInterfaces:()[Ljava/lang/Class;
8: astore_1
9: aload_0
10: invokevirtual #3 // Method java/lang/Class.getSuperclass:()Ljava/lang/Class;
13: astore_0
14: goto 0
17: return
LineNumberTable:
line 6: 0
line 7: 4
line 11: 9
line 12: 14
line 13: 17
apparently "Eclipse has implemented its own compiler called as Eclipse Compiler for Java (ECJ)." ( What is the difference between javac and the Eclipse compiler? )... what I would like to know is if there is any option to use in Eclipse to have the same bytecode produced by javac.