Binary compatibility issue an example?

As far as I understand the source compatibility and how you can easily show an example that would break source compatibility (change name of the method, remove method etc.), I am having a bit of a problem seeing how binary compatibility can be broken in practice. Does anyone have a simple example of preservation of source compatibility that would cause binary compatibility issues i.e. no code changes are required but recompilation is necesssary?

Jon Skeet
people
quotationmark

One example (and this is by no means the only one) would be if the signature of a method in a library changes, in a compatible way. For example, consider:

// Library.java v1
public class Library {
    public static void print(String foo) {
        System.out.println(foo);
    }
}

// Client.java v1
public class Client {
    public static void main(String[] args) {
        Library.print("hello");
    }
}

Compile and run:

$ javac Client.java Library.java
$ java Client
hello

Now change Library.java - note the type of the foo parameter:

// Library.java v2
public class Library {
    public static void print(Object foo) {
        System.out.println(foo);
    }
}

Just recompile Library.java and try to rerun Client:

$ javac Library.java 
$ java Client
Exception in thread "main" java.lang.NoSuchMethodError: Library.print(Ljava/lang/String;)V
    at Client.main(Client.java:3)

people

See more on this question at Stackoverflow