toArray (original) (raw)

Brian Goetz brian.goetz at oracle.com
Sat Dec 15 16:08:42 PST 2012


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.)



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