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 ...
随机推荐
- 【贪心大水题】BZOJ3410-[Usaco2009 Dec]Selfish Grazing 自私的食草者
[题目大意] 给出n个区间,问最多选取多少个区间使得它们互相不重叠. [思路] 水题quq改善心情用.按照右端点大小排序,每次更新上一次的右端点,如果当前左端点大于上次右端点可取. #include& ...
- uoj386 【UNR #3】鸽子固定器
link (似乎很久没写题解了) 题意: n个物品,每个物品有a,b两个值,给定A,B,现在最多选其中m个,要求最大化选出的物品中[b权值和的B次方-a极差的A次方]. $n\leq 2\times ...
- C#双面打印解决方法(打印word\excel\图片)
最近需要按顺序打印word.excel.图片,其中有的需要单面打印,有的双面.网上查了很多方法.主要集中在几个方式解决 1.word的print和excel的printout里设置单双面 2.prin ...
- 为什么java的构造方法中this()或者super()要放在第一行
java的构造方法中如果自己显性的调用super()的时候一定要放在第一行,如不是的话就会报错. 为什么一定要在第一行? super()在第一行的原因就是: 子类有可能访问了父类对象, 比如在构造函数 ...
- hdu 5207 Greatest Greatest Common Divisor 数学
Greatest Greatest Common Divisor Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/ ...
- Java常量字符串String理解 String理解
以前关于String的理解仅限于三点:1.String 是final类,不可继承2.String 类比较字符串相等时时不能用“ == ”,只能用 "equals" 3.Strin ...
- Android 开源项目android-open-project解析之(四) ColorPickView,GraphView,UI Style,Other
十三.ColorPickView ColorPickerView 颜色选择器,支持PopupWindows或新的Activity中打开 项目地址:https://code.google.com/p/c ...
- 多线程间通信之AutoResetEvent和ManualResetEvent的原理分析和开发示例
AutoResetEvent 允许线程通过发信号互相通信. 通常,当线程需要独占访问资源时使用该类. 线程通过调用 AutoResetEvent 上的 WaitOne 来等待信号. 如果 AutoRe ...
- Linux下查找命令(收集整理)
原文:http://blog.csdn.net/sunstars2009918/article/details/8510878 一.Linux查找文件的相关命令 常 用 命 令 简要中文说明 程序所在 ...
- pm2-web
A web based monitor for PM2. Multiple hosts With the release of 0.11 pm2 no longer uses TCP sockets ...