有一个Java Void- 大写的V-- 引用类型.我见过它唯一的情况是参数化Callables
final Callable<Void> callable = new Callable<Void>() {
public Void call() {
foobar();
return null;
}
};
Run Code Online (Sandbox Code Playgroud)
Java Void引用类型还有其他用途吗?可以分配除了以外的任何东西null吗?如果是的话,你有例子吗?
说我有以下代码:
import java.lang.InterruptedException;
import javax.swing.SwingWorker;
public class Test
{
private JDialog window;
public Test
{
// instantiate window
}
private class Task extends SwingWorker<Void, Void>
{
public Void doInBackground()
{
try { Thread.currentThread().sleep(5000); }
catch(InterruptedException e) {}
return null;
}
}
public void doTask()
{
Task task = new Task();
task.execute();
}
protected void process()
{
// update various GUI components here
}
public static void main(String args[])
{
Test t = new Test();
t.doTask();
System.out.println("done");
}
}
Run Code Online (Sandbox Code Playgroud)
我需要等到t.doTask() …