toArray (original) (raw)

Remi Forax forax at univ-mlv.fr
Sun Dec 16 07:09:37 PST 2012


On 12/16/2012 04:01 PM, Brian Goetz wrote:

This works if you're willing to throw static type safety out the window; we have no compile-time guarantee that U[] is compatible with elements of type T.

yes, it's pragmatic choice. Few years back, i realize that a lot of Java developers never seen an ArrayStoreException or have trouble to remember the last time they saw one.

Rémi

On 12/16/2012 5:30 AM, Remi Forax wrote: On 12/16/2012 01:08 AM, Brian Goetz wrote: Seems that the minimally invasive version of toArray (that doesn't propagate the horrible convention established by Collection, and yet doesn't foist Object[] on users) is:

interface Stream { Object[] toArray(); T[] toArray(Class clazz); } It is unfortunate to need the Object[] version at all. However, code that is generic in T might be passed a Stream and not know what class literal to use. It is further unfortunate that we cannot say S[] toArray(Class clazz) as then such code could say toArray(Object.class), but we cannot (this is a limitation of generics.)

why not ? interface Stream { U[] toArray(Class clazz); } Rémi



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