I have a simple java project which I am using ant to build. It has these two classes:
A.java:
public class A {
public static void main(String[] args) {
Integer i = 0;
B.f(i);
}
}
B.java:
public class B {
public static void f(int i) {
System.out.println("hello");
}
}
Which works fine:
$ ant compile
[...]
$ java -cp bin A
hello
Now, if I change the int
parameter in B.f
to an Object
:
public class B {
public static void f(Object i) {
System.out.println("hello");
}
}
...the code recompiles fine...
$ ant compile
[...]
$ java -cp bin A
Exception in thread "main" java.lang.NoSuchMethodError: B.f(I)V
at A.main(Unknown Source)
... but it crashes at runtime. Why?
Folder structure before compilation:
bin
build.xml
src
├── A.java
└── B.java
build.xml:
<project>
<target name="compile">
<javac srcdir="src" destdir="bin"/>
</target>
</project>