检验莫以对象是否为某中指定的类型,通常用在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
关键字 instanceof
最新推荐文章于 2024-05-02 00:37:44 发布