THE METHOD SIGNATURE INCLUDES THE RETURN TYPE.
The compiler ignores it when has to check for duplicates. For Java is illegal to have two methods with the signature differing only by the return type.
Try that:
public class Called {
public String aMethod() {
return "";
}
}
public class Caller {
public static void main(String[] main) {
aMethod();
}
public static void aMethod() {
Called x = new Called();
x.aMethod();
}
}
Build the project, go to bin directory, copy the Caller.cass somewhere. Then change the called method:
public int aMethod() {
return 0;
}
Build the project, you will see that both Called.class and Caller.class have a new timestamp. Replace the Caller.class above and run the project. You'll have an exception:
java.lang.NoSuchMethodError: it.prova.Called.aMethod()Ljava/lang/String;