Different kinds of compatibility

Given version 1.0 of an interface, adding a method to produce version 1.1 is:


a binary-compatible change
Pre-existing binaries (i.e. clients compiled against interface 1.0) continue to link against the changed type (i.e. interface 1.1).

a behavior-compatible change
Pre-existing binaries (i.e. clients compiled against interface 1.0) do not use the new method so do not rely on its return values or side-effects.

not a source-compatible change
Pre-existing sources (i.e. implementations of interface 1.0) will not compile against the changed type (i.e. interface 1.1).

not a migration-compatible change
Sources that migrate to the new type (i.e. to use interface 1.1) will not link against the old type (i.e. interface 1.0).

Migration compatibility is the least understood and the most interesting. It concerns how a type is used, and is discussed in JLS 4.7 in the context of generics. It essentially means that:


  1. if a library is updated, pre-existing clients should continue to link with it
  2. if a client is updated, pre-existing libraries should continue to link with it

Adding a method to an interface is not migration-compatible because a client updated to use interface 1.1 will receive a NoSuchMethodError if it calls a 1.1-only method on a class that implements 1.0.

Comments:

What do you think the best solution is? LayoutManager2 extended LayoutManager to add new methods, but I don't think that's a good one to repeat. Perhaps a builder approach is better, with a concrete type at the end of it, rather than an interface, such as: LayoutManager manager=builder.layoutContainer({Container c => code to layout a container here}).getPreferredSize(#orAMethodLiteral); I find that I haven't finished thinking if I have an interface with more than one method, and if I get down to an interface with one method, it may as well be replaced by a generic Function type. Except that generics don't do varargs, so if the method takes more than one parameter, things get messy.

Posted by Ricky Clarkson on March 19, 2007 at 03:31 AM PDT #

Post a Comment:
Comments are closed for this entry.
About

Alex Buckley is the Specification Lead for the Java language and JVM at Oracle.

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
Feeds