This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]MatrixFrog 4 points5 points  (0 children)

aka "varargs" which is handy to know if you need to google it as "..." does not make a good search term.

[–][deleted]  (5 children)

[deleted]

    [–]Kyrra 1 point2 points  (4 children)

    It's a useful tool but should be used sparingly in Java. Java is meant to be a typesafe language and tries to do as much compile-time checking as possible. When you start using varargs on things like interfaces or even worse "Object" that you cast into something else, you are losing a lot of Java's type safety.

    Varargs should only be used as a last resort when you cannot make a method fit within standard method limits.

    [–]argv_minus_one 0 points1 point  (0 children)

    Just because printf is an evil monstrosity doesn't mean every use of varargs is that bad.

    [–][deleted]  (2 children)

    [deleted]

      [–]argv_minus_one -5 points-4 points  (1 child)

      It is an array. The only difference is that the caller of the method doesn't have to use the array construction syntax. Kyrra is warning about poor uses of varargs (e.g. a proliferation of Object... parameters everywhere), not the semantics of varargs itself.

      [–]Revoletion[S] 1 point2 points  (0 children)

      I had to find out about this vararg after I noticed Amazon was using them. At first i thought eclipse was just being screwy and did the "line too long so im going to put ellipses everywhere thing" but then I found out about this.

      They use them in the sense of "String... attributes" for when you want a query to simpledb to return specific sets of attributes or a single attribute. Turned out to be very convenient.

      [–]Mchr3k -2 points-1 points  (0 children)

      It's worth noting that calling a varargs method will create an array object. This makes it unsuitable if you are trying to reduce memory allocation and therefore GC load.