Tuesday, November 08, 2011

Usefull Generics

This is quite useful:


    public static <T> List<T> asList(T... obj) {
        List<T> result = new ArrayList<T>();
        Collections.addAll( result, obj );
        return( result );
    }

asList(a,b,c,d,e);

3 Comments:

Anonymous Mars said...

or Arrays.asList( new Foo[] { a, b, c } );

12:25 PM  
Blogger jerdavis said...

I used to use that.. then I also added asSet, and dropped the Array creation.

12:29 PM  
Blogger jerdavis said...

Looks like Arrays.asList(T... ) takes varargs already ...

12:36 PM  

Post a Comment

<< Home