用于Java Void参考类型? [英] Uses for the Java Void Reference Type?
问题描述
有一个Java Void
- 大写V-- 引用类型。我见过的唯一情况是参数化可调用
s
There is a Java Void
-- uppercase V-- reference type. The only situation I have ever seen it used is to parameterize Callable
s
final Callable<Void> callable = new Callable<Void>() {
public Void call() {
foobar();
return null;
}
};
Java Void还有其他用途
参考类型?是否可以分配 null
以外的任何内容?如果是的话,你有例子吗?
Are there any other uses for the Java Void
reference type? Can it ever be assigned anything other than null
? If yes, do you have examples?
推荐答案
Void
已成为惯例对于您不感兴趣的泛型参数。没有理由要使用任何其他非实例化类型,例如 System
。
Void
has become convention for a generic argument that you are not interested in. There is no reason why you should use any other non-instantiable type, such as System
.
它也常用于例如 Map
值(尽管 Collections.newSetFromMap
使用 Boolean
因为地图不必接受 null
values)和 java.security.PrivilegedAction
。
It is also often used in for example Map
values (although Collections.newSetFromMap
uses Boolean
as maps don't have to accept null
values) and java.security.PrivilegedAction
.
I wrote a weblog entry on Void
a few years back.
这篇关于用于Java Void参考类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!