Introduce Covariance/Contravariance at declaration site for Java 9 ?

Dan Smith daniel.smith at oracle.com
Thu Oct 18 12:20:40 PDT 2012


I think it's a good idea, at least worth serious consideration.

There would be no _requirement_ to design libraries in declaration-site-friendly ways, but the fact is we already have _lots_ of types that are inherently co-/contra- variant, and the "right" way to use those types is to always use a wildcard.  It turns into a mechanical transformation that obscures the code behind layers of wildcards and pointlessly punishes users if they mess up; it would sure be nice to remove that burden from clients of variant types.

Anyway, I can say it's on the radar.  But maybe we will conclude it's a horrible idea; or maybe other things will take priority.

—Dan

On Oct 15, 2012, at 6:24 PM, Joshua Bloch <josh at bloch.us> wrote:

> I believe that declaration site variance annotations are every bit as bad as use-site annotations.  They're bad in a different way--they force you to write idiosyncratic types because natural types don't lend themselves to fixed variance restrictions--but they're still bad. Providing both use and declaration site variance in one language is the worst of both worlds (unless you're trying to kill the language).
> 
>     Josh
> 
> On Mon, Oct 15, 2012 at 3:09 PM, Remi Forax <forax at univ-mlv.fr> wrote:
> I've just read the presentation of Stuart Marks at JavaOne [1],
> all examples after slide 32, the first one that use lambdas are not written correctly
> because all method signatures do not use wildcards.
> 
> Brian, I know that we will not be able to introduce covariance/contravariance
> at declaration site for Java 8, so the solution we will deliver will be far from perfect
> because nobody understand wildcards.
> Is there a way to free Dan and Maurizio  enough time to investigate if
> covariance/contravariance can be added to Java 9.
> 
> Rémi
> [1] https://stuartmarks.wordpress.com/2012/10/07/javaone-2012-jump-starting-lambda-programming/
> 
> 



More information about the lambda-libs-spec-observers mailing list