The instanceof Keyword
来源:互联网 发布:总后勤部职工数据库 编辑:程序博客网 时间:2024/05/18 02:45
http://www.java2s.com/Tutorial/Java/0060__Operators/TheinstanceofKeyword.htm
The instanceof keyword can be used to test if an object is of a specified type.
public class MainClass { public static void main(String[] a) { String s = "Hello"; if (s instanceof java.lang.String) { System.out.println("is a String"); } }}
Output: is a String.
However, applying instanceof on a null reference variable returns false.
public class MainClass { public static void main(String[] a) { String s = null; if (s instanceof java.lang.String) { System.out.println("true"); } else { System.out.println("false"); } }}output: false
class Parent { public Parent() { }}class Child extends Parent { public Child() { super(); }}public class MainClass { public static void main(String[] a) { Parent p = new Child(); if (p instanceof Parent) { System.out.println("true"); } }}output: true
- The instanceof Keyword
- The explicit Keyword
- About the keyword Synchronized
- The const keyword
- The 'this' keyword
- The Java synchronized keyword
- The instance of keyword
- The coproc keyword
- The cregister Keyword
- native, The Keyword Of Java
- the this keyword in javascript
- Using the C "volatile" Keyword
- the usage of keyword const
- The volatile keyword in Java
- Introduction to the Volatile Keyword
- Day3-10.The static keyword
- Day14-47.The this keyword
- The Usage of the volatile Keyword
- 黑马程序员java学习<基础加强>—泛型
- String与,StringBufferStringBuilder的区别?
- 程序中避免使用magic number
- C#中如何获取存储过程的输出参数值
- 黑马程序员java学习<基础加强>—JavaBean
- The instanceof Keyword
- akari(2011iooo)的格式化后的代码
- SQL中的where条件,在数据库中提取与应用浅析
- 解决jQuery和其它库的冲突
- 解读MySQL事务的隔离级别和日志登记模式选择技巧
- Struts2(5):Action中直接访问Servlet API---实现XxxAware接口
- 黑马程序员——java学习5(获取数组最值)
- JW Player, FLV Player 字幕
- Struts2(6):使用ServletActionContext访问Servlet API