On 8 August 2010 21:28, James Carman <ja...@carmanconsulting.com> wrote:
> On Sun, Aug 8, 2010 at 1:25 PM, sebb <seb...@gmail.com> wrote:
>>
>> As it stands, the code allows calls of the form:
>>
>> Map<Integer,Integer> map = ArrayUtils.toMap(new String[][] {{"foo",
>> "bar"}, {"hello", "world"}});
>>
>> without complaining.
>>
>> Failing to check the types of the array entries on creation means that
>> the error may lie undetected until much later, making it potentially
>> much harder to debug.
>>
>
> I am not against checking against the type arguments, but this change
> assumes the user won't do something stupid.

Or ignorant, as the type requirements are not documented.

> It'd be a ClassCastException later, yes.  Having the type arguments only 
> allows
> the user not to have to cast the return type.  They can use type
> inference.

Yes.

But the current change makes it harder to find errors.

Previously, the compiler would warn about unsafe casts; with the
current implementation the warnings are suppressed.
IMO this is a retrograde step.

I expect generic library routines to create a Map that agrees with the
generic types, not allow the types to be violated.

Generics are partly about allowing the compiler to check that class
casts cannot happen.
This relies on generic methods behaving themselves, which the current
implementation does not.

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
> For additional commands, e-mail: dev-h...@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to