In Java, is it possible to cast to void (not Void)?
Is there anything I can put in X, to make the follow work:
Object o = (void) 开发者_开发知识库X;
void is notionally a primitive. (though most would disagree it is even that I suspect) You cannot cast an object to it.
The closest you can come to this is an InvocationHandler can return null
for a void method and a void method invoke()ed via reflection will return null
.
Maybe this discussion might be of interest:
Uses for the Java Void Reference Type?, it covers about everything you can do with Void
and what it's good for.
Java is not C++. In Java, void is not a type, it is a placeholder that means "no return value".
No. You can set x = null;
if you wish though?
精彩评论