Migrating methods in Collections

Brian Goetz brian.goetz at oracle.com
Tue Dec 22 18:30:56 UTC 2015


> 1. While language-level extension methods (no JVM involvement) won’t 
> solve the deprecated-method problem, they do solve the Stream<int>.sum 
> problem, and quite elegantly.

Sort of -- but only if you buy the partiality.

In order for this to work, you have to (as .NET does) inject methods 
into *types*, not into *classes*.  This is just a partial method in 
disguise!  In order for this to work, you have to be comfortable with 
the idea that the set of methods on a given receiver is dependent on the 
parameterization of the receiver.  And you clearly are, since you don't 
think extension methods are too complex.

FTR, we considered and rejected use-site extension methods in 8, for a 
philosophical reason that is still equally valid here: an API developers 
should own their API.  What we rejected is the use-site aspect of it; 
the part we actually liked (but didn't have enough motivation to embrace 
in 8) was the partiality.  Just as default methods support the 
after-the-fact aspect of API extension that use-site extension would 
(without the transparency risks), partial methods (including partial 
defaults) support the specialized-receiver aspect of extension methods 
that we like but don't yet have.




More information about the valhalla-spec-experts mailing list