CHAPTER 13: Binary Compatibility Previous
Previous
Java Language
Java Language
Index
Index
Next
Next

13.5 Evolution of Interfaces

13.5.1 public Interfaces , 13.5.2 Superinterfaces , 13.5.3 The Interface Members , 13.5.4 Field Declarations , 13.5.5 Abstract Method Declarations

This section describes the impact of changes to the declaration of an interface and its members on pre-existing binaries.


13.5.1 public Interfaces

Changing an interface that is not declared public to be declared public does not break compatibility with pre-existing binaries.

If an interface that is declared public is changed to not be declared public , then an IllegalAccessError is thrown if a pre-existing binary is linked that needs but no longer has access to the interface type, so such a change is not recommended for widely distributed interfaces.


13.5.2 Superinterfaces

Changes to the interface hierarchy cause errors in the same way that changes to the class hierarchy do, as described in S13.4.4. In particular, changes that result in any previous superinterface of a class no longer being a superinterface can break compatibility with pre-existing binaries, resulting in a VerifyError .


13.5.3 The Interface Members

Adding a member to an interface does not break compatibility with pre-existing binaries.

Deleting a member from an interface may cause linkage errors in pre-existing binaries. If the example program:

interface I { void hello(); }
class Test implements I {


	public static void main(String[] args) {
		I anI = new Test();
		anI.hello();
	}
	public void hello() { System.out.println("hello"); }
}

is compiled and executed, it produces the output:

hello

Suppose that a new version of interface I is compiled:

interface I { }

If I is recompiled but not Test , then running the new binary with the existing binary for Test will result in a NoSuchMethodError . (In some early implementations of Java this program still executed; the fact that the method hello no longer exists in interface I was not correctly detected.)


13.5.4 Field Declarations

The considerations for changing field declarations in interfaces are the same as those for static final fields in classes, as described in S13.4.7 and S13.4.8.


13.5.5 Abstract Method Declarations

The considerations for changing abstract method declarations in interfaces are the same as those for abstract methods in classes, as described in S13.4.13, S13.4.14, S13.4.20, and S13.4.22.

Top© 1996 Sun Microsystems, Inc. All rights reserved.