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

前端 未结 5 2145
青春惊慌失措
青春惊慌失措 2020-11-22 06:23

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

public MessageBuilder withRecipientJids(JID... recipientJids         


        
5条回答
  •  孤街浪徒
    2020-11-22 06:59

    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

提交回复
热议问题