Object对象检测

来源:互联网 发布:js怎么设置div隐藏 编辑:程序博客网 时间:2024/05/12 15:53
        String test="你好";
        //test(test);
        
        Map<String,String> map=new HashMap<String,String>();
        
        map.put("groupName", "groupName-1");
        map.put("type",1+"");

        test(map);



检测如下:

    public static void test(Object obj){
        if(obj instanceof String){
            System.out.println("字符串对象");
        }if(obj instanceof Map){
            System.out.println("Map对象");
        }else{
            System.out.println("其他对象");
        }
    }

2 0
原创粉丝点击