As you can see here in documentation that there are 11 methods named of
in Set
:
static <E> Set<E> of()
static <E> Set<E> of(E e1)
static <E> Set<E> of(E e1, E e2)
//similar 8 methods like above till e10
Now coming to the 12th var-args
method:
static <E> Set<E> of(E... elements)
The method in second snippet essentially does the same as those methods in the first snippet. My question is, why did Java developers included the 11 arbitrary methods(first snippet) in Set
interface? Do we really need those methods when we have a var-args
method?
And which method will be invoked if I pass only one argument to of
?
static <E> Set<E> of(E e1)
or static <E> Set<E> of(E... elements)
.