Platypus Header

Platypus Innovation Blog

13 October 2014

Broken by default: Java 8 is not quite backwards compatible

Java 8 introduces several nice features, one of which is the default keyword. This is close to having mix-ins (aka traits; inheriting code from multiple parents) which is great. It also lets you add new methods to an old interface without breaking existing implementations. Or that's what it's meant to do.

But Oracle have broken backwards compatibility.

It is an error for a class to inherit a default method from two parents. If that happens, then the class must override the default method to specify what happens.

But if the default method involves a Java 8 class, then implementing it will break your code for Java 7.

I encountered this because we have a class which implements both List and Set. It's now impossible to do that if your code has to work across Java 7 and 8. To work in Java 8, it has to implement spititerator(), but that will break Java 7 which knows nothing of the Splititerator class.

No comments:

Post a comment

Good-Loop Unit