Default Methods
Interface methods with implementation (Java 8+)
4 min read
Default Methods
Default methods allow interfaces to have method implementations.
Code Examples
Default method in interface
java
1
2interface Logger {
3 default void log(String msg) {
4 System.out.println(msg);
5 }
6}
7
8class AppLogger implements Logger {}
9 Use Cases
- Backward compatibility
- Optional behavior
Common Mistakes to Avoid
- Ignoring default method conflicts
- Overusing default methods