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

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

问题描述

我不熟悉doInBackground(Params... params)

这种东西叫什么,我该如何使用?

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

推荐答案

正如 devA 和 VVV 所说,这称为varargs".实际上,以下两行代码是等效的:

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) {

方法内部的代码是一样的,但是当它被调用时,它们的调用方式会不同.第一个需要像这样调用:

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... params)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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