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

前端 未结 5 2225
青春惊慌失措
青春惊慌失措 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:46

    It means that the method accepts a variable number of arguments ("varargs") of type JID. Within the method, recipientJids is presented.

    This is handy for cases where you've a method that can optionally handle more than one argument in a natural way, and allows you to write calls which can pass one, two or three parameters to the same method, without having the ugliness of creating an array on the fly.

    It also enables idioms such as sprintf from C; see String.format(), for example.

提交回复
热议问题