JDK-4858556 : generics+variance: arrays as bounds
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: solaris_8
  • CPU: generic
  • Submitted: 2003-05-05
  • Updated: 2006-12-06
  • Resolved: 2006-12-06
Related Reports
Relates :  
Relates :  
Description
We've had a lot of trouble with Collection.toArray.  Here's the
original, non-generic signature

    Object[] toArray(Object[] a)

This misses two important features of the API.  First, the
object parameter must be capable of receiving elements of
the collection type.  Second, the return type is the same
as the parameter type.  When we added generics, we changed
this to

    <T> T[] toArray(T[] a)

a little better in that it captures the second but not the
first property.  With variance, the signature from Denmark
is

    E[-] toArray(E[-] a)

This captures the first property, but not the second.  For
example, you can't read elements from the returned array,
which makes this fairly useless.  I think the correct
signature should be

    <T extends E[-]> T toArray(T a)

This signature is precise and captures both essential
features of the API.  Unfortunately, this isn't currently
allowed by the syntax.  I think it should be allowed.

Comments
EVALUATION Variance is gone, for array types and otherwise.
06-12-2006