TimurMahammadov / google-collections

Automatically exported from code.google.com/p/google-collections
Apache License 2.0
0 stars 0 forks source link

Forwarding collections should use wildcard constructors #86

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The forwarding collections should all have constructors that take
"compatible" parameters. For example, instead of 

  ForwardingList( List<E> delegate )

it should be

  ForwardingList( List<? extends E> delegate )

The current constructor requires a wrapper or copy to use compatible
collections.

Original issue reported on code.google.com by codemon...@gmail.com on 25 Jun 2008 at 4:05

GoogleCodeExporter commented 9 years ago
For mutable collections, your suggestion would break type safety.

For example, suppose delegate was a List<Integer> and the ForwardingList was a
List<Number>. The ForwardingList.add() method would accept a Double, which 
would lead
to a Double being stored in the List<Integer>.

However, we plan to add wild cards to unmodifiable collections, since that 
problem
doesn't arise. See 
http://code.google.com/p/google-collections/issues/detail?id=79

Original comment by jared.l....@gmail.com on 25 Jun 2008 at 4:28