JEP proposal: Improved variance for generic classes and interfaces

Dan Smith daniel.smith at oracle.com
Mon Oct 27 22:52:35 UTC 2014


> On Oct 26, 2014, at 4:53 PM, elias vasylenko <eliasvasylenko at gmail.com> wrote:
> 
> Just a quick question/suggestion: it seems like a handy side-effect of the proposed changes is the potential for relaxation of the limitation on reimplementation of interfaces with different generic parametrisations, and I'm wondering if you've considered this.
> 
> For example, it should be possible to allow something like this:
> 
>     class Foo implements Predicate<Integer> {}
> 
>     class Bar extends Foo implements Predicate<Number> {}
> 
> Since declaration-site variance guarantees compatibility of the overriding parametrisation. Of course we can't technically override test(Integer) with test(Number)... but from an outsiders perspective I don't see this as incompatible with current language design philosophy... At any rate, covariance should be more straightforward
> 
> I'm sure this would have come up if it hasn't already, but I couldn't find any explicit mention of it.

That's a good idea, and not something we've looked into yet.  Thanks for the suggestion.

—Dan


More information about the compiler-dev mailing list