commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Carman <ja...@carmanconsulting.com>
Subject Re: svn commit: r983137 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java
Date Mon, 09 Aug 2010 22:44:51 GMT
On Mon, Aug 9, 2010 at 7:32 AM, sebb <sebbaz@gmail.com> 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", Color.red },
  { "blue", Color.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", Color.red },
  { "blue", Color.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 =
MapUtils.builder().put("red", Color.red).put("blue",
Color.blue).toMap();

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

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


Mime
View raw message