Let's say I have a simple class
public class A {
public int inc(int k, int i){
System.out.println(i);
return 0;
}
}
And I call it from Main
public class Main {
public static void main(String[] args) {
new A().inc(0,7);
}
}
The corresponding java bytecode (javap -c A.class
):
public class A {
public A();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public int inc(int, int);
Code:
0: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
3: iload_2
4: invokevirtual #3 // Method java/io/PrintStream.println:(I)V
7: iconst_0
8: ireturn
}
Note the iload_2
.
Now let's remove the unnecessary parameter k
.
public class A {
public int inc(int i){
System.out.println(i);
return 0;
}
}
and of course
public class Main {
public static void main(String[] args) {
new A().inc(7);
}
}
Now if I re-run the code, A will be compiled to
public class A {
public A();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public int inc(int);
Code:
0: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
3: iload_1
4: invokevirtual #3 // Method java/io/PrintStream.println:(I)V
7: iconst_0
8: ireturn
}
Which is what I'd expect. However, let's say I don't want to re-run everything and am just interested in the bytecode-level changes ...
gradle compileJava
and then
javap -c A.class
it will not have changed.
And in fact, upon checking gradle output, there's a
:compileJava UP-TO-DATE
There that clearly doesn't belong there.
Now, I've created the project with the Intellij (2017.2.4) wizard, (gradle project with Java as "additional libraries and frameworks", using SDK1.8), added the Main
and A
classes, and tested this.
What do I need to change to make this work the way it's supposed to?