commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Carman <>
Subject Re: svn commit: r983137 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/
Date Mon, 09 Aug 2010 03:45:03 GMT
On Sun, Aug 8, 2010 at 10:04 PM, sebb <> wrote:
> 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.

With type erasure, I believe it's impossible (correct me if I'm
wrong)to determine the exact type of "K" and "V" in the code so that
we could check the type safety of the keys/values passed in.  So, we
would either have to change the method signature to:

public Map<K,V> toMap(Class<K> keyType, Class<V> valueType, Object[] array);

or, we could add a warning to the documentation for the method:

"Warning: This code does not (and cannot) check the type safety of the
keys/values against the method's type variables (<K,V>).  Thus, if you
are expecting a Map<String,String> to be returned, but you pass in a
MapEntry<String,Integer>[] (or the analogous Object[][]), the method
will not fail, but you will get a ClassCastException at runtime."

Other than that, the only other option that I can see is to back out
the change completely, but then we lose the "syntactic sugar" that it
adds.  I personally like the sugar.  So, I'd say let's go with the
warning in the docs.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message