Simplifying reified generics with partial specialization

Ron Pressler ron at paralleluniverse.co
Mon Jan 5 15:23:50 UTC 2015


> The issue is that you can do things with ArrayList<Integer> that you
can't do with ArrayList<int>.
> What will happen when you do call "list.add(null)"?

Why, you'd get an NPE, of course! While ArrayList<int> would be a
List<Integer>, it will *not* be an ArrayList<Integer>. And a List<Integer>
is certainly allowed (it even says so in the spec) to throw an NPE when a
null element is added, or a ClassCastException when a wrong type is added.
This would be the exact same behavior as trying to auto-unbox a null
Integer into an int, or insert the wrong type into an array.


Ron Pressler
paralleluniverse.co
@puniverseco <https://twitter.com/puniverseco> on Twitter

On Mon, Jan 5, 2015 at 5:07 PM, Simon Ochsenreither <simon at ochsenreither.de>
wrote:

> This would mean that ArrayList<int> will implement List<Integer> (and will
>> therefore extend List and List<?>) and Object will essentially be the Any
>> type (and List<int>, if allowed, would just be an alias for
>> List<Integer>).
>>
> The issue is that you can do things with ArrayList<Integer> that you can't
> do with ArrayList<int>.
> What will happen when you do call "list.add(null)"? Will it take the array
> of ints, allocate a new array of Integers, box all ints to Integers and
> copy them over to the new reference array, then add null as the last
> element?
>
> (I think I already mentioned an example where such issues get even more
> pronounced in one of my earlier emails. E. g. what's supposed to happen if
> you add a String to your specialized covariant immutable data-structure of
> ints? If you suggest that if a generic parameter is instantiated with a
> value type the generic bounds are collapsed, then that's what Brian was
> saying in the beginning.)
>


More information about the valhalla-dev mailing list