java.lang.Void and void
java.lang.Void is analogous to java.lang.Integer. Integer is a way of boxing values of the primitive type int. Void is a way of boxing values of the primitive type void.
"But wait, void doesn't have any possible values!"
Right! That's what makes java.lang.Void "uninstantiable". :)
It's a nice feature of the Java type system that every primitive type has a boxed equivalent. inthas Integer, long has Long, byte has Byte... and void has Void. It would be weird and asymmetrical if Void didn't exist.
"So what's the difference between java.lang.Void and void?"
Easy. void is a primitive type. Void is an reference type that inherits from Object. They're similar in that neither of them has any possible values; but nevertheless they are two very different types, from the type system's point of view.
"But I don't have any use for Void in my programs."
And I don't have any use for GarbageCollectorMXBean in mine. Some features don't have non-obscure uses. That's okay.
The only point of Void is to hold Void.TYPE, which is sort of like void.class. If you have a reflective reference to a method that returns void, and you get its return type, it'll return Void.TYPE.
java.lang.Void and void的更多相关文章
- 利用泛型抽取Dao层,加事务注解问题(java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType)
想利用泛型抽取BaseDao层,简化操作时出现故障: @Transactional这个注解是能够继承的.于是就想写在抽取的BaseDao层上,让实现的类能够不用写@Transactional,就可开启 ...
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.love5/com.example.love5.Main11Activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.
若有 java.lang.RuntimeException和 java.lang.NullPointerException: Attempt to invoke virtual method 'voi ...
- void java.lang.System.gc()
void java.lang.System.gc() Runs the garbage collector. Calling the gc method suggests that the Java ...
- Java 源码赏析 - java.lang - Void
被人鄙视了,于是也来读读源码... package java.lang; /** * The Void class is an uninstantiable placeholder class to ...
- Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setDisplayShowHomeEnabled(boolean)' on a null object reference
/********************************************************************************* * Caused by: java ...
- Caused by: java.lang.IllegalArgumentException: Modifying queries can only use void or int/Integer as return type!
Caused by: java.lang.IllegalArgumentException: Modifying queries can only use void or int/Integer as ...
- java.lang.IllegalAccessException: void #####.MyBroadcastReceiver.() is not accessible from jav
java.lang.IllegalAccessException: void #####.MyBroadcastReceiver.<init>() is not accessible fr ...
- java.lang.Void类源码解析_java - JAVA
文章来源:嗨学网 敏而好学论坛www.piaodoo.com 欢迎大家相互学习 在一次源码查看ThreadGroup的时候,看到一段代码,为以下: /* * @throws NullPointerEx ...
- JAVA:从public static void main(String args[])開始
我们都知道当你要执行一个JAVA文件的时候必需要有一个main函数. 这是为什么呢? 跟C语言的道理一样,当你执行一个文件的时候.你必需要有一个入口函数或者入口地址,在C里面是main函数.相同的在J ...
随机推荐
- 理解HashSet及使用
(1) 为啥要用HahSet? 假如我们现在想要在一大堆数据中查找X数据.LinkedList的数据结构就不说了,查找效率低的可怕.ArrayList哪,如果我们不知道X的位置序号,还是一样要全 ...
- ACM -- 算法小结(二)错排公式的应用
pala提出的问题: 十本不同的书放在书架上.现重新摆放,使每本书都不在原来放的位置.有几种摆法? 这个问题推广一下,就是错排问题: n个有序的元素应有n!种不同的排列.如若一个排列式的所有的元素都 ...
- struts2自动接收表单数据
提交页面主要代码: <form method="post" action="messageAction"> <input type=&qu ...
- sublime在高分辨率屏幕下,左侧边栏字体问题
因为新的笔记本是1920*1080分辨率的屏幕,在打开sublime的时候,侧边栏的文件夹名字会变得很小,虽然很清晰,但是太小了看起来很吃力, 如下图所示 网上找了很多的方法试了好久没有成功,一天闲下 ...
- shell练习题
一.编写一个脚本使我们在写一个脚本时自动生成”#!/bin/bash”这一行和注释信息. 原文代码为: Shell 1 2 3 4 5 6 7 8 9 10 #!/bin/bash ...
- java读写锁实现数据同步访问
锁机制最大的改进之一就是ReadWriteLock接口和它的唯一实现类ReentrantReadWriteLock.这个类有两个锁,一个是读操作锁,另一个是写操作锁.使用读操作锁时可以允许多个线程同时 ...
- arcengine帮助http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/what_s_new_for_developers_at_10_/0001000002zp000000/
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/what_s_new_for_develope ...
- ios修改textField的placeholder的字体颜色、大小
textField.placeholder = @"username is in here!"; [textField setValue:[UIColor redColor] fo ...
- 为jquery ajax请求增加正在运行提示
在jquery源码中增加showMask()方法调用: if ( xhrSupported ) { jQuery.ajaxTransport(function( options ) { // Cros ...
- BIG5, GB(GB2312, GBK, ...), Unicode编码, UTF8, WideChar, MultiByte, Char说明与区别
汉语unicode编译方式,BIG5是繁体规范,GB是简体规范 GB是大陆使用的国标码,BIG5码,又叫大五码,是台湾使用的繁体码. BIG5编码, GB编码(GB2312, GBK, ...), U ...