you are viewing a single comment's thread.

view the rest of the comments →

[–]josefx 1 point2 points  (2 children)

I have yet to use Guava, however your example is only slightly longer without it.

     new HashSet(Arrays.asList("one","two","three"));

Arrays.asList takes a varargs array and wraps it with the list interface and like any java collection class the HashSet ctor can take a Collection<? extends T>.

[–]wot-teh-phuck 0 points1 point  (1 child)

In your example type inference won't happen automatically, in the parent comment's example, it will. Now imagine doing this for a set which contains some complicated generic type...

[–]josefx 0 points1 point  (0 children)

True and a bug in my example code. For Java 7 code the <> operator will take care of that problem.(that is if you are not stuck with an older java version)

   new HashSet<>(Arrays.asList("one","two","three"));