Doug pointed out something to me today that hadn't occurred to me -- that callers of Collection<int>.toArray() might actually *want* an Object[], not an int[]. Does anyone have opinions on usages that would inform this one way or the other?

Now that we have streams, we can easily get both:

    Collection<int> c = ...
    c.stream().toArray()   // int[]
    c.stream().boxed().toArray()  // Object[]
    c.stream().boxed().toArray(Integer[]::new)  // Integer[]

So it would even be possible (though a little weird) to completely punt on migrating toArray() and tell users to go through streams if they want an array.


Reply via email to