AsyncTask的的doInBackground(参数... PARAMS) [英] AsyncTask's doInBackground(Params... params)

查看:506
本文介绍了AsyncTask的的doInBackground(参数... PARAMS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不熟悉的 doInBackground(参数... PARAMS)

这是什么类型的东西叫,以及如何利用它?

What is this type of thing called, and how do I utilize it?

推荐答案

随着德瓦和VVV说,被称为可变参数。实际上,下面两行code是等价的:

As devA and VVV have said, that is called "varargs". Effectively, the following two lines of code are equivalent:

public void makeLemonade(String[] args) {

public void makeLemonade(String... args) {

该方法内的code将是相同的,但是当它被调用时,它们将被称为不同。第一个需要被称为是这样的:

the code inside the method would be the same, but when it was called, they would be called differently. The first would need to be called like this:

makeLemonade(new String[]{"lemon1", "lemon2", "lemon3"});

,而第二个的方法,签名可以具有0到的参数(一个假定的)无限数量,但是他们都需要是字符串参数。下面所有的调用将工作:

while the second one's method signature could have 0 to (an assumed)infinite number of arguments, but they would all need to be String arguments. All of the following calls would work:

makeLemonade("lemon1");
makeLemonade("lemon4", "lemon7", "lemon11", "lemon12"); 
makeLemonade();
// ... etc ...

两者之间的细微差别是,你可以,如果你使用的是可变参数调用makeLemonade()依法在这里。

A subtle difference between the two is that you can call makeLemonade() legally here if you're using varargs.

这篇关于AsyncTask的的doInBackground(参数... PARAMS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆