关于instanceof

来源:互联网 发布:詹姆斯12年总决赛数据 编辑:程序博客网 时间:2024/06/10 02:16
public class Test {

    public static void main(String[] args)
    {
        Object obj = new String();
       
        System.out.println(obj instanceof String);
        System.out.println(obj instanceof Integer);
        System.out.println(obj instanceof Book);
    }
    class Book
    {

    }
}

 

 

结果为:true,false,false

但是如果这样写则不会通过编译:

System.out.println(new Integer() instanceof String);