BinaryCompatibleDefaultMethods

From APIDesign

(Difference between revisions)
Jump to: navigation, search

JaroslavTulach (Talk | contribs)
(New page: DefaultMethods are useful when one desperately needs to add a method into an existing '''interface'''. However, they decrease clarity of a ProviderAPI. As such, don't overuse. ...)
Next diff →

Revision as of 06:02, 28 September 2020

DefaultMethods are useful when one desperately needs to add a method into an existing interface. However, they decrease clarity of a ProviderAPI. As such, don't overuse. Morever it has been recently demonstrated that adding DefaultMethods can even compromise BinaryCompatibility.


Recently Emilian Bold asked me to participate in a tweeting about binary incompatibility caused by adding CharSequence.isEmpty in JDK15. An interesting case. Following code compiles on JDK8 to JDK14:

public interface ArrayLike {
  int length();
 
  default boolean isEmpty() {
    return length() == 0;
  }
}
 
class CharArrayLike implements CharSequence, ArrayLike {
  private final char[] chars;
 
 
}
Personal tools
buy