Android AsyncTask 裡面可以看到有一個傳入的參數型態是 ...,像是

protected Long doInBackground(URL... urls) 

其實他是 Java 的 Varargs,以下有一段精闢的解釋。

The underlying type of a variadic method function(Object... args) is function(Object[] args). Sun added varargs in this manner to preserve backwards compatibility.
-- StackOverflow Can I pass an array as arguments to a method with variable arguments in Java?

所以如果是上面的例子,我可以如以下這樣做。其他例子可以參考 integer array static initialization.

URL[] urls = new URL[]{ "your_url_1", "your_url_2", "your_url_3" };

Comments

comments powered by Disqus
Copyright © 2013 Andro Chen
Powered by Logdown and Greyshade
Favicon from The Noun Project