jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jukka Zitting <jukka.zitt...@gmail.com>
Subject Re: Generics generator class
Date Mon, 04 May 2009 15:03:40 GMT

On Mon, May 4, 2009 at 3:17 PM, Thomas Müller <thomas.mueller@day.com> wrote:
> I propose to add a new 'generics generator class' called 'New' to
> jackrabbit-jcr-commons. It would contain constructor methods for the
> most commonly used collection objects.
> public class New {
>    public static <K, V> HashMap<K, V> hashMap() {
>        return new HashMap<K, V>();
>    }
>    public static <T> ArrayList<T> arrayList() {
>        return new ArrayList<T>();
>    }
>    public static <T> WeakReference<T> weakReference(T t) {
>        return new WeakReference<T>(t);
>    }
>    ...
> }
> What do you think? Are there better solutions?

I like the idea, removing clutter is good.

A related common annoyance I run into is about creating an initialized

    List<String> abc = Arrays.asList(new String[] { "a", "b", "c" });


    List<String> abc = new ArrayList() {{ add("a"); add("b"); add("c"); }};

This would be quite a bit more convenient with a utility method like this:

    List<String> abc = New.list("a", "b", "c");

Felix has a point about the drawbacks of such utility code, but in
this case I tend to think that it's probably worth it. The potential
savings in extra typing/reading are probably quite a bit larger than
the amount of extra utility code needed.

PS. This might also be a good idea for inclusion in the upcoming
Commons Lang 3.0 version that'll be based on Java 5.


Jukka Zitting

View raw message