Integer 为空赋值给int
2015-12-15 11:19
441 查看
今天遇到了一个异常,将Integer的值赋值给int时不会自动将Integer 的null转化为0,而是报运行时异常,空指针
public static void main(String[] args) throws Exception { Integer i = null; test(i); System.out.print(i); } public static void test(int i){ System.out.print(i); int n = 0; n = i; System.out.print(n); } public static void main(String[] arg){ int i = 0; test(i); Map<Long,Integer> map = new HashMap<Long,Integer>(); map.put((long) 1, null); test2(map.get(1)); } public static void test(Integer id){ System.out.print("+++++++++++++++++" + id); } public static void test2(Integer id){ int i = id; System.out.print(id); }
相关文章推荐
- hdu 5596 GTW likes gt
- hdu 5596 GTW likes gt
- html5桌面通知
- Json Serialize 忽略特定属性
- [How to] UILocalNotification 的使用
- 在北京创业三个月的惨痛经历
- Centos Linux中VMware虚拟机为磁盘空间的扩容
- python 错误提示
- Kinect for Windows SDK开发入门(十):手势识别 上:基本概念
- ubuntu系统安装360 wifi2(兼容小米wifi和百度wifi http://blog.sina.com.cn/s/blog_6ad624380102v7k0.html
- HTTP 1.1与HTTP 1.0的比较
- 从 UIWebView 到 WKWebView
- ionic 发布 android apk
- Chrome 中的 JavaScript 断点设置和调试技巧
- Socket通信总结(附C++实现)
- 【转】Pro Android学习笔记(十二):了解Intent(下)
- angularjs中ng-route和ui-router简单用法的代码比较
- GetFiles GetDirectories 获取文件名,目录名排序
- http协议及web服务原理
- Installshie安装