Combine guava's ImmutableList and varargs
Posted
by
Stas Kurilin
on Stack Overflow
See other posts from Stack Overflow
or by Stas Kurilin
Published on 2010-12-25T19:37:11Z
Indexed on
2010/12/25
19:54 UTC
Read the original article
Hit count: 473
I want create constructor that will take one or more integers and save it into field as ImmutableList. According to "The right way to use varargs to pass one or more arguments" by Bloch's Item 42 I create smt like
class Foo{
private final ImmutableList<Integer> bar;
public Foo(Integer first, Integer... other) {
this.bar = ImmutableList.<Integer>builder()
.add(first)
.addAll(Arrays.asList(other))
.build();
}
}
Why builder doesn't get generic automatically? And, as it smells. How I can rewrite it?
© Stack Overflow or respective owner