Problem of defender methods with generic methods
Alex Buckley
alex.buckley at oracle.com
Mon Nov 15 14:30:54 PST 2010
Hi Steven,
On 11/15/2010 5:46 AM, Steven Simpson wrote:
> It's more plausible, then, that the API writer would use one of the
> following options:
>
> 1. Just use List<? extends Comparable> in the interface, with
> Collections.max(..) in the implementation.
> 2. As above, but with static extension methods (but still no dynamic
> dispatch on the max call itself).
> 3. Add a List defender that imposes additional constraints on <T>, as
> Ali Ebrahimi seems to have tried to do.
Just to clarify, for (2), do you mean adding an extension method to
interface List<T>:
public interface List<T> {
<A extends Comparable<? super A>>
extension A max()
default Collections.<A>max;
}
(By "no dynamic dispatch on the max call", I presume you mean a scenario
where there is no CustomizedList<T> to override List<T>'s max.)
And furthermore not introducing CustomizedList<T>
?
Alex
More information about the lambda-dev
mailing list