« Easier Google cache hacking | Main | MacHack room partner wanted »

Java interface troubles

From Java Preferences API:

Why is Preferences an abstract class rather than an interface? It was decided that the ability to add new methods in an upward compatible fashion outweighed the disadvantage that Preferences cannot be used as a "mixin".

You can't add new methods reliably to an interface? Why is that so?

Comments

Binary compatibility. If your class implements Preferences but Sun adds a new method to Preferences in 1.5, your class will fail to load until you add an implementation of that method to your class and recompile your application.

On the other hand, if Preferences is an abstract class, Sun can add new non-abstract methods without breaking applications that inherit from Preferences.

Ah... Thank you.

Post a comment