Tuesday 19 May 2015

Java Interface Default Methods. What?

In my last post I’ve presented both traits and mixins, with the promise of identifying the Java 8 Interface Default Methods. So, let’s get on it.

First of all, if you don’t know what I’m talking about, read my previous post -and please ignore the fact that it took me almost half a year to write this second part :)

A quick summary:
  • Mixins: Abstract subclasses. You can call super from inside the mixin, and can define both methods and variables. Mixins automatically solves conflict by linearization (inserting the mixin in the method lookup chain from left to right).
  • Traits: Allow us to define behaviour outside the class, but don’t define state. The methods defined in the trait «have the same semantics» as the method defined in the class (Flattening property). It’s like they were copied into the class. You have to handle conflicts by yourself.

Now we can fully dive into Java Interface default methods, reading the post here :)