jinge jinge - 6 months ago 12
Java Question

Is Interface API always constant?

Such as

java.util.Set<E>
, is it guaranteed to be constant? "Constant" means that the author will never add or delete or modify the current interface methods. So that my classes implemented it can always work.

In fact, I am thinking about the risks when I use "Composition" instead of "Inheritance". (Effective Java Item 16) Once
Set
API changes, the code will broken.

Answer

Is Interface API always constant?

I assume that you are asking if the Set API can ever be changed in an incompatible way.

The only people who can actually guarantee that are Oracle.

I have not seen any guarantees (in writing) from Oracle, but based on past history, there is ZERO chance that they would alter the Set API in a way that would impact binary compatibility for user code.

In short: don't worry about it. Certainly for any of the standard interfaces1 in Java SE.


1 - The internal interfaces are a different matter; e.g. any APIs in the sun.* package tree. However, if you use them that's one of the risks that you are taking. Beware!