`
ivywjhua
  • 浏览: 21578 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

java null cast

阅读更多
摘自 Java Language Specification
The null reference can always be cast to any reference type.In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.

Object obj = null;
String str = (String) obj;
Integer a = (Integer) obj;
//int b = a;
//NullPointerException


还有一种用法
doSomething( (MyClass) null );

If doSomething is overloaded, you need to cast the null explicitly to MyClass so the right overload is chosen:
详细见:
http://stackoverflow.com/questions/315846/why-null-cast
但是并没有所说的warning
分享到:
评论

相关推荐

    javacv-platform-1.3.3-src

    // We can "cast" Pointer objects by instantiating a new object of the desired class. CvHaarClassifierCascade classifier = new CvHaarClassifierCascade(cvLoad(classifierName)); if (classifier.isNull...

    java面试800题

    Q0041 Java保留字 11个:byValue, cast, false, future, generic, inner, operator, outer, rest, true, var. Q0042 Java的值传递的规则? Java基本类型的都是值传递,对象使用的都是引用传递 Q0043 java相关概念 ...

    googleGson JsonObject json转换包

    包含以下java源文件: com.google.gson.DefaultDateTypeAdapter.class com.google.gson.ExclusionStrategy.class com.google.gson.FieldAttributes.class com.google.gson.FieldNamingPolicy.class ...

    Thinking in Java 4th Edition

    Java SE5 and SE6 .................. 2 Java SE6 ......................................... 2 The 4th edition........................ 2 Changes .......................................... 3 Note on the ...

    worldwindjava源码-kotlin:kotlin通用语法

    world wind java 源码 kotlin kotlin common grammer Kotlin的优点 可读性更高,更简洁,使用Kotlin,可以更容易的避免创建模版型代码,因为大多数经典的情景都默认包含在Kotlin中 ...cast. We don´t

    Java中的基本数据类型转换

    如果想要做ORM,将数据映射为对象,则基本的数据类型转换是必要的功能,而Java似乎未提供该功能,只有自己下手来完成该功能.  完成该功能的目标如下:  1: 提供基本的数据转换  2: 考虑转换的性能.  下面是我...

    JSTL详细标签库介绍

    java异常处理的基础:<BR><BR>java的异常处理适用于在一个方法中能够检测出错误单不能处理错误的情况,这样方法将抛出一个异常(JAVA无法保证“存在”的异常处理程序能够处理某种异常,若“存在”,就“捕获”异常,...

    解决出现Incorrect integer value: ” for column ‘id’ at row 1的问题

    解决出现Incorrect integer value: ” for column ‘id’ at row 1的问题 前言: 今天在学习Python的过程中操作数据库,遇到了一个问题,执行sql语句插入数据的时候报错Incorrect integer value: ” for column ‘id...

    mysql官方中文参考手册

    7.2.7. MySQL如何优化IS NULL 7.2.8. MySQL如何优化DISTINCT 7.2.9. MySQL如何优化LEFT JOIN和RIGHT JOIN 7.2.10. MySQL如何优化嵌套Join 7.2.11. MySQL如何简化外部联合 7.2.12. MySQL如何优化ORDER BY 7.2.13. ...

    MYSQL中文手册

    7.2.7. MySQL如何优化IS NULL 7.2.8. MySQL如何优化DISTINCT 7.2.9. MySQL如何优化LEFT JOIN和RIGHT JOIN 7.2.10. MySQL如何优化嵌套Join 7.2.11. MySQL如何简化外部联合 7.2.12. MySQL如何优化ORDER BY ...

    MySQL 5.1参考手册中文版

    7.2.7. MySQL如何优化IS NULL 7.2.8. MySQL如何优化DISTINCT 7.2.9. MySQL如何优化LEFT JOIN和RIGHT JOIN 7.2.10. MySQL如何优化嵌套Join 7.2.11. MySQL如何简化外部联合 7.2.12. MySQL如何优化ORDER BY ...

    MySQL 5.1参考手册

    7.2.7. MySQL如何优化IS NULL 7.2.8. MySQL如何优化DISTINCT 7.2.9. MySQL如何优化LEFT JOIN和RIGHT JOIN 7.2.10. MySQL如何优化嵌套Join 7.2.11. MySQL如何简化外部联合 7.2.12. MySQL如何优化ORDER BY 7.2.13. ...

    MySQL5.1参考手册官方简体中文版

    7.2.7. MySQL如何优化IS NULL 7.2.8. MySQL如何优化DISTINCT 7.2.9. MySQL如何优化LEFT JOIN和RIGHT JOIN 7.2.10. MySQL如何优化嵌套Join 7.2.11. MySQL如何简化外部联合 7.2.12. MySQL如何优化ORDER BY 7.2.13. ...

    MySQL 5.1中文手冊

    7.2.7. MySQL如何优化IS NULL 7.2.8. MySQL如何优化DISTINCT 7.2.9. MySQL如何优化LEFT JOIN和RIGHT JOIN 7.2.10. MySQL如何优化嵌套Join 7.2.11. MySQL如何简化外部联合 7.2.12. MySQL如何优化ORDER BY 7.2.13. ...

    mysql5.1中文手册

    CAST() 10.4.4. SHOW语句 10.5. Unicode支持 10.6. 用于元数据的UTF8 10.7. 与其它DBMS的兼容性 10.8. 新字符集配置文件格式 10.9. 国家特有字符集 10.10. MySQL支持的字符集和校对 ...

    MySQL 5.1参考手册 (中文版)

    7.2.7. MySQL如何优化IS NULL 7.2.8. MySQL如何优化DISTINCT 7.2.9. MySQL如何优化LEFT JOIN和RIGHT JOIN 7.2.10. MySQL如何优化嵌套Join 7.2.11. MySQL如何简化外部联合 7.2.12. MySQL如何优化ORDER BY 7.2.13. ...

    MySQL 5.1官方简体中文参考手册

    7.2.7. MySQL如何优化IS NULL 7.2.8. MySQL如何优化DISTINCT 7.2.9. MySQL如何优化LEFT JOIN和RIGHT JOIN 7.2.10. MySQL如何优化嵌套Join 7.2.11. MySQL如何简化外部联合 7.2.12. MySQL如何优化ORDER BY 7.2.13. ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    Friends Exceptions Run-Time Type Information (RTTI) Casting Streams Preincrement and Predecrement Use of const Integer Types 64-bit Portability Preprocessor Macros 0 and NULL sizeof Boost C++0x ...

    网管教程 从入门到精通软件篇.txt

    CST:Macromedia Director Cast文件 CUR:Windows光标文件 D DBF:dBASE文件,一种由Ashton-Tate创建的格式,可以被ACT!、Lipper、FoxPro、Arago、Wordtech、Xbase和类似数据库或与数据库有关产品识别;可用数据...

Global site tag (gtag.js) - Google Analytics