Transparency
John Nilsson
john at milsson.nu
Wed Jul 14 13:24:32 PDT 2010
On Wed, Jul 14, 2010 at 12:16 AM, Nathan Bryant
<nathan.bryant at linkshare.com> wrote:
> John,
>
> If you mean what I think you mean, that seems to result in a generics that is useful only for interface definition. Either it's not possible to write:
>
> foo = new ArrayList<int>()
>
> Or doing so results in autoboxing to Integer, unbeknownst to the user, which is a serious violation of the principle of least surprise.
Or there is some clever hacks in ArrayList to handle the issue. An
empty array is just empty, so no need to have any specific array-type.
If the first element added is an int or Integer you could
optimistically assume that all input will be ints and thus allocate an
int[], should that assumption turnout to be wrong, in later adds you
allocate an Object[].
I can see how this could be problematic for uninitialized values,
return null or 0? Maybe this could be solved by adding a generic
"zero"-value that is valid for all types?
I'm not saying that this is particularily elegent though...
BR,
John
More information about the lambda-dev
mailing list