The instance of keyword
来源:互联网 发布:solarman软件下载 编辑:程序博客网 时间:2024/05/01 17:45
The keyword instanceOf in java programming language is a boolean operator that is used to test whether an object is of an specified type or not and returns the value accordingly.
The keyword instanceOf in java programming language is a boolean operator that is used to test whether an object is of an specified type or not and returns the value accordingly.Keywords are basically reserved words which have specific meaning relevant to a compiler. It takes an object reference as its first reference and a class or interface as its second operand and produces a result true or false based on the condition. It also lets the developer to create their own type classes having runtime behavior specified by the developer. aMoneyType, aDateType, aCheckingAccountID, etc are some to the examples of the such type of classes.
Syntax: Here is the syntax for using aninstanceOf keyword
if (node instanceof TreeNode){
/ write your code here
}
Where, condition (node instanceOf TreeNode) returns true if the class node is an instance or is an instance of a subclass of TreeNode.
Example: Here is the example how the instanceOf operator is used.
public class MainClass {
public static void main(String[] a) {
String s = "Hello";
if (s instanceof java.lang.String) {
System.out.println("is a String");
}
}
}
It returns the output "is a String" after checking the condition because the condition returns true.
Note: Here are some points which must be noted.
- While applying the instanceOf operator on a null reference then it returns false.
转自:http://www.roseindia.net/help/java/i/instanceof-keyword.shtml
- The instance of keyword
- native, The Keyword Of Java
- the usage of keyword const
- The Usage of the volatile Keyword
- The operation order of instance creation
- The instance of singleton in application of Tracing-Files
- Use of Explicit keyword
- Summary of keyword synchronized
- The explicit Keyword
- About the keyword Synchronized
- The const keyword
- The 'this' keyword
- The Java synchronized keyword
- The instanceof Keyword
- The coproc keyword
- The cregister Keyword
- An easy instance of using the template class in C++
- The memory size of a C++ object instance.
- linux配置java环境变量(详细)
- 项目中图片不显示
- C#线程与异步调用
- 老白Oracle数据库性能优化实务-视频分享
- haffman树
- The instance of keyword
- 十六进制颜色对照表
- js验证大全(转)
- Cocos2D_X中的文本操作(LibJson)
- 【LeetCode】 Subsets Subsets II
- Oracle常用SQL(DDL)命令
- Java中二维数组的长度
- ubuntu 13.10 & Ubuntu 14.04 64位安装及配置 google拼音输入法及Adobe flash player、mp3 插件安装、中文GBK编码等
- EASYUI+MVC4+VS2010通用权限管理系统开发