关键字 instanceof

来源:互联网 发布:js set to array 编辑:程序博客网 时间:2024/05/19 19:57

检验莫以对象是否为某中指定的类型,通常用在if语句中:
if (objectReference instanceof type)
eg:
String s =”Hello”;
if (s instanceof java.lang.String);
返回为true;
String s =null;
if (s instanceof java.lang.String);
返回为false;
Child child = new Child();
if (child instaceof Parent)//返回为true

原创粉丝点击