Brian

26%
Flag icon
When there is an obvious implementation of an interface method in terms of other interface methods, consider providing implementation assistance to programmers in the form of a default method. For an example of this technique, see the removeIf method on page 104. If you provide default methods, be sure to document them for inheritance using the @implSpec Javadoc tag (Item 19).
Brian
How different really is interfaces with default implementations from multiple inheritance though? No state I guess, that’s a good point.
Robert
· Flag
Robert
A type of scenario that's come to mind during the past month which seems like a great candidate for default methods are callback interfaces with multiple methods. Sometimes such interfaces have, say, …
Brian
· Flag
Brian
Yes, the pattern where there are multiple callbacks and default is noop for each makes sense. I like it a lot. I guess I could conceive of a case in which you’d have two interfaces providing the callb…
Robert
· Flag
Robert
> I guess I could conceive of a case in which you’d have two interfaces providing the callback pattern on the same class, though it seems a little contrived.

It's pretty typical to do this in Android; …
Effective Java
Rate this book
Clear rating
Open Preview