Public Defender Methods: A Good Idea?
At the moment, if you need to extend functionality, you can create static methods, much like Collections does with it's reverse method. This has the issue that you cannot override the reverse method for your own collections implementation. And more to the point, wouldn't it be nice to have a reverse() method in the List itself?
The proposal would result in syntax that looks as follows:
public interface List<T> extends Collection<T>
public int size();
// The rest of the existing Set methods
extension void reverse() default Collections.<T>reverse;
This would mean that you could extend the reverse method yourself if you wish. If you don't want to, the functionality would default to calling another methods (in this case Collections.reverse()).
Is this something you'd want to do? I don't think I'd like to see the addition myself. I prefer simple, unambiguous code. If I break an interface, clients of that interface need to deal with the change. At least it makes it very clear that the contract has changed.