Search code examples
javaellipsis

What is the ellipsis (...) for in this method signature?


In the App Engine docs, what is the ellipsis (JID...) for in this method signature?

public MessageBuilder withRecipientJids(JID... recipientJids)

What's the function of those three dots?


Solution

  • Those are Java varargs. They let you pass any number of objects of a specific type (in this case they are of type JID).

    In your example, the following function calls would be valid:

    MessageBuilder msgBuilder; //There should probably be a call to a constructor here ;)
    MessageBuilder msgBuilder2;
    msgBuilder.withRecipientJids(jid1, jid2);
    msgBuilder2.withRecipientJids(jid1, jid2, jid78_a, someOtherJid);
    

    See more here: http://java.sun.com/j2se/1.5.0/docs/guide/language/varargs.html