Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Default methods were added to let the JDK evolve interfaces, but teams now use them to put large amounts of behaviour into interfaces. What org-wide guidance would you set, and what long-term costs are you guarding against?

Default methods were designed for interface evolution and small conveniences built on an interface's abstract methods. Putting heavy behaviour in them creates multiple inheritance of behaviour with conflict rules every reader must know, and because defaults cannot hold state, complex logic ends up in awkward patterns such as exposed state accessors or static helpers. My guidance would be: defaults for evolution and thin conveniences, real behaviour in classes that implementers compose, and any new default on a widely implemented interface reviewed as an API change.

Why this question is asked

Once teams discover that interfaces can carry code, some start using them as mixins: an interface with fifteen default methods that a class implements to pick up a bundle of behaviour. It feels convenient, because Java allows only one superclass but many interfaces. A few years later, the costs show up as confusing overrides, hidden coupling and logic that is hard to test. Interviewers ask this at principal level because setting guidance like this means explaining the long-term cost to many teams who see only the short-term convenience. In this answer, we will recall what defaults were for, look at how heavy defaults go wrong, set clear guidance, and decide how to roll it out.

1What Default Methods Were Designed For

A default method is an interface method with a body that implementing classes inherit. Java 8 introduced it so the JDK could add methods such as Collection.stream and Iterable.forEach to interfaces that millions of classes already implemented, without breaking them. The defaults the JDK added are mostly thin: forEach is a loop over iterator(), Comparator.reversed wraps this, Map.getOrDefault calls get and containsKey.

So the original design had two uses in mind: letting an interface evolve compatibly, and offering small conveniences expressed entirely through the interface's own abstract methods. Neither use involves state, and neither needs much code.

2How Heavy Defaults Show Up

Here is the kind of code that prompts this question. A team wants every service to get retry, metrics and caching behaviour, so they put it in interfaces.

Java
public interface Cached<K, V> {
V load(K key);
Map<Object, Map<Object, Object>> CACHES = new ConcurrentHashMap<>(); // shared by everyone
@SuppressWarnings("unchecked")
default V get(K key) {
Map<Object, Object> mine = CACHES.computeIfAbsent(this, t -> new ConcurrentHashMap<>());
return (V) mine.computeIfAbsent(key, k -> load((K) k)); // no eviction, no size limit
}
}
public interface Retrying { default <T> T withRetry(Supplier<T> s) { /* 40 lines */ return s.get(); } }
public interface Metered { MeterRegistry registry(); default void count(String n) { registry().counter(n).increment(); } }
public class PriceService implements Cached<String, Price>, Retrying, Metered { /* ... */ }

Notice the workaround for state. The interface cannot have fields, so the cache lives in a static map keyed by the implementing object, which means every instance is held forever, a memory leak, and the cache has no eviction. Metered asks implementers to expose a registry() accessor publicly, only so the default can reach it. These are the awkward patterns that appear whenever stateful behaviour is forced into an interface.

3The Long-Term Costs We Are Guarding Against

The first cost is multiple inheritance of behaviour. A class that implements five behaviour-laden interfaces gets its methods from five places, and when two of them define the same default, or a superclass has a method with the same signature, Java's resolution rules decide which runs: class methods win, then the most specific interface, otherwise a compile error. Every reader must know those rules to understand what a call does, and an upgrade of one interface can change behaviour in classes nobody looked at.

The second cost is the lack of state, which we just saw, leading to static registries, leaks and accessors that expose internals. The third is API surface. Every default method is public and becomes part of the type for every implementer and every caller, so a helper that was meant to be internal is now something other teams depend on and that we cannot change freely. And the fourth is testing: behaviour mixed into the class through an interface cannot be replaced with a test double in isolation, whereas a collaborator object can.

Mixin interfaces versus composed classes
ConcernBehaviour in defaultsBehaviour in composed classes
StateNone; static maps or exposed accessorsPrivate fields, normal lifecycle
Where a call goesResolution rules across interfacesThe field's type, visible in code
Public surfaceEvery default is public APIOnly what we choose to expose
TestingHard to replace in isolationPass a fake collaborator
Changing it laterAffects every implementerAffects users of that class

4The Guidance We Set

The rule I would publish is short. Use default methods for two things: adding a method to an existing interface compatibly, and thin conveniences, a few lines, built only on the interface's abstract methods, such as an overload with a default argument or a combinator like andThen. Put real behaviour, anything with state, I/O, configuration or more than a handful of lines, in classes, and let implementers use them by composition.

Java
// After: behaviour lives in classes that are composed in
public final class PriceService {
private final Cache<String, Price> cache; // e.g. Caffeine, with size and expiry
private final Retry retry; // e.g. a Resilience4j Retry
private final MeterRegistry metrics;
public PriceService(Cache<String, Price> cache, Retry retry, MeterRegistry metrics) { /* ... */ }
public Price price(String sku) {
metrics.counter("price.lookups").increment();
return cache.get(sku, k -> retry.executeSupplier(() -> client.fetch(k)));
}
}

Every dependency is now visible in the constructor, each one has its own state and lifecycle, and tests can pass fakes. The interfaces that remain are small types, with perhaps a default convenience or two.

5Treating a New Default as an API Change

The last part of the guidance protects shared interfaces. Adding a default to an interface that many classes implement looks harmless, since it compiles everywhere, but it is a behaviour change for every implementer. An existing method with the same signature silently becomes its override, a generic algorithm may be wrong for an implementation with locking or caching rules, and another interface adding the same default breaks builds. So for any interface implemented outside its own module, a new default goes through the same review as any other API change: search for clashing methods, document whether implementations should override it, and announce it in release notes.

6Rolling the Guidance Out

We do not rewrite every existing mixin at once. We publish the guidance with before and after examples from our own code, add it to the review checklist, and fix the worst cases first, which are usually those holding state in static maps, because they are actual leaks. New interfaces follow the rule from day one, and existing ones are refactored when teams touch them.

To keep it from drifting, a simple automated check helps, for example a test that scans the codebase's interfaces with reflection, using Method.isDefault(), and flags interfaces with many default methods or static mutable fields for review. The aim is not to ban defaults, which are useful, but to make heavy use visible so it is a decision, not a habit.

7Follow-up questions

Are default methods ever right for larger behaviour?

Occasionally, when the behaviour is entirely derived from the abstract methods and has no state, such as a family of query helpers over a small primitive interface. Even then, the skeletal class pattern, an abstract class that implements the interface, is often clearer, because it can also hold state and override equals and hashCode.

What do you say to a team that uses defaults to avoid single inheritance limits?

That the limit is pointing at a real design choice. If a class needs behaviour from several sources, composition gives it that without the conflict rules: hold several collaborators and delegate. It makes the dependencies explicit, which is exactly what reviewers and tests need.

How do default methods interact with Spring proxies?

Spring's proxies call default methods normally, so annotations such as @Transactional on an interface default can work, but where Spring looks for annotations depends on the proxy type and version, so check your version. This is another reason to keep important behaviour in classes, where annotation placement is unambiguous.

8Conclusion

In this answer, we saw that default methods were designed for compatible interface evolution and thin conveniences built on abstract methods. Heavy behaviour in defaults brings multiple inheritance of behaviour with resolution rules readers must know, forces state into static registries or exposed accessors, enlarges public API and makes testing harder. The guidance is to keep defaults thin, put real behaviour in classes composed by implementers, review any new default on a widely implemented interface as an API change, and roll it out by fixing the worst stateful cases first.

What to say in the interviewAbout 90 seconds aloud

Open with

I'd start by reminding teams what defaults were for: the JDK needed to add methods like stream and forEach to interfaces millions of classes implemented, so defaults let interfaces evolve compatibly and offer small conveniences built from the abstract methods.

Then, if they want more

They were never meant to carry state or large behaviour. When teams use them as mixins, we pay several long-term costs. You get multiple inheritance of behaviour, so understanding a call means knowing the resolution rules: class wins, then the most specific interface, otherwise a compile error, and upgrading one interface can change classes nobody looked at.

Because defaults can't hold state, people invent static maps keyed by the instance, which leak memory, or public accessors that expose internals just so a default can reach them. Every default is public API for every implementer, and mixed-in behaviour is hard to replace in tests. So my guidance would be short.

Defaults are for compatible evolution and thin conveniences of a few lines built only on the abstract methods. Real behaviour with state, I/O or configuration goes in classes that implementers compose through their constructors. And any new default on an interface implemented outside its module is reviewed as an API change.

I'd roll it out with examples from our code, fix the stateful leaks first, refactor the rest as teams touch them, and add a simple scan to keep heavy use visible.

About this answer

Last updated
12 November 2026
Versions it names
Java 8
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Default methods were added to let the JDK evolve interfaces, but teams now use them to...": https://scrivio-interview-library.netlify.app/java/interfaces-and-abstract-classes/e302394b38/