[External] : Re: ReversibleCollection proposal

Stuart Marks stuart.marks at oracle.com
Wed Apr 21 18:53:25 UTC 2021


On 4/19/21 2:01 PM, Remi Forax wrote:
> ----- Mail original -----
> Thinking a little bit about your proposal,
> introducing an interface right in the middle of a hierarchy is not a backward compatible change
> (you have an issue when the compiler has to use the lowest upper bound).
> 
> By example
>    void m(List<Collection<String>> list) { ... }
> 
>    var list = List.of(new LinkedHashSet<String>(), List.of("foo"));
>    m(list);  // does not compile anymore
> 
> currently the type of list is List<Collection<String>> but with your proposal, the type will be List<ReversibleCollection<String>>

Yes, interesting. Not too difficult to fix though. Either change the method 
declaration to

     void m(List<? extends Collection<String>> list)

or change the 'var' to an explicit declaration of List<Collection<String>>.

s'marks


More information about the core-libs-dev mailing list