Java 8 introduced default methods on interfaces to provide backwards compatibility for implementations of the collections interfaces, to avoid MethodNotFound errors on legacy libraries.
i.e A library with a java 7 implementation of List will not implement the stream() method. If java 8 code uses this library the default implementation provides a fall-back.
What I see in practice is many developers are using this feature over-zealously to emulate mix-ins and multiple inheritance in a style that resembles scala traits.
One of my concerns is that this style of programming blurs the line between interfaces (i.e. contracts) and their implementations and therefore introduces hidden tight coupling and violates inversion of control, forcing me to use back doors to test the code by overriding the default implementations in my unit tests, to suppress behavior that should not be present at the unit test level.
Is this use of default methods an anti-pattern, or am I alone in suspecting this?
default
methods feature, as your title suggests, or is it about the “style of programming” that you “see in practice”, described in the body of your question? – Possessive