Closed GoogleCodeExporter closed 9 years ago
If you're using Java7+, you're best bet is to use the diamond operator and
Arrays.asList():
import static java.util.Arrays.asList;
...
import java.util.LinkedHashSet;
import java.util.Set;
...
Set<Element> mySet = new LinkedHashSet<>(asList(e1, e2, e3, e4, ...));
In fact, we'll probably be removing most of the static factory methods from
Lists/Sets/Maps at some point in the future.
Original comment by kak@google.com
on 26 Mar 2014 at 4:17
Don't forget: the most common fix is just to switch to ImmutableSet.of(e1, e2,
...).
Original comment by kevinb@google.com
on 26 Mar 2014 at 4:21
It seems to me the whole point of those static methods is to reduce boilerplate
noise. Surely you don't think the code in your comment is neater than:
Sets.newLinkedHashSet(e1,e2,e3, ...)
There is also the fact that Arrays.asList creates a whole new object which
Sets.newHashSet avoids.
Original comment by NikolayM...@gmail.com
on 26 Mar 2014 at 4:24
I hadn't thought of ImmutableSet. Thanks kevinb.
Original comment by NikolayM...@gmail.com
on 26 Mar 2014 at 4:26
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:09
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:07
Original issue reported on code.google.com by
NikolayM...@gmail.com
on 26 Mar 2014 at 4:08