commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: svn commit: r983137 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java
Date Mon, 09 Aug 2010 02:04:48 GMT
On 8 August 2010 21:28, James Carman <james@carmanconsulting.com> wrote:
> On Sun, Aug 8, 2010 at 1:25 PM, sebb <sebbaz@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-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

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


Mime
View raw message