gpt4 book ai didi

java - java泛型中声明类型void的目的

转载 作者:行者123 更新时间:2023-12-01 18:35:43 25 4
gpt4 key购买 nike

我正在经历vogella's tutorial我可以解决这个问题:

private class DownloadWebPageTask extends AsyncTask<String, Void, String> {

我不确定这个 void 意味着什么以及为什么要使用它?

最佳答案

让我们看一下 AsyncTask 的文档:

The three types used by an asynchronous task are the following:

  • Params, the type of the parameters sent to the task upon execution.
  • Progress, the type of the progress units published during the background computation.
  • Result, the type of the result of the background computation.

Not all types are always used by an asynchronous task. To mark a type as unused, simply use the type Void:

private class MyTask extends AsyncTask<Void, Void, Void> { ... }

Void只是一个类型参数,类似于您给出 IntegerFloat 等的方式。

关于java - java泛型中声明类型void的目的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22132321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com