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 22:44:51 GMT
On Mon, Aug 9, 2010 at 7:32 AM, sebb <> wrote:
> Why not split the code into two methods:
> public static <K,V> Map<K, V> toMap(Map.Entry<K,V>[] array)
> and
> public static <K,V> Map<K, V> toMap(Class<K> keyType, Class<V>
> valueType, Object[][] array)

So, what would that make the "user" code look like?  The whole reason
for this, unless I'm mistaken, was to make it easy to do stuff like:

public static final Map<String,Color> COLOR_MAP = ArrayUtils.toMap(new
Object[][] {
  { "red", },
  { "blue", }
} );

To me, we're really trying to make it easier to use this API, right?
So, now the code would look like:

public static final Map<String,Color> COLOR_MAP =
ArrayUtils.toMap(String.class, Color.class, new Object[][] {
  { "red", },
  { "blue", }
} );

This is one of the big gripes about how generics are handled in Java,
you have to repeat yourself so darn much.  What if we told folks to
use a new MapBuilder instead?

public static final Map<String,Color> COLOR_MAP =

It seems like this "builder" stuff is getting popular these days.
What do you guys think?

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

View raw message