java – 如何找出对象是整数还是isa字符串或isa布尔值?

我有一个对象,我想检测什么类型,所以我可以打电话
if (obj isa Integer)
  put(key,integerval);  
if (obj isa String)
    put(key,stringval);  
if (obj isa Boolean)
    put(key,booleanval);

解决方法

你真的很亲密!
if (obj instanceof Integer)
    put(key,integerval);  
if (obj instanceof String)
    put(key,stringval);  
if (obj instanceof Boolean)
    put(key,booleanval);

JLS 15.20.2

RelationalExpression instanceof ReferenceType

At run time,the result of the instanceof operator is true if the value of the RelationalExpression is not null and the reference Could be cast (§15.16) to the ReferenceType without raising a ClassCastException. Otherwise the result is false.

看看你的使用模式,但是,看起来你可能会遇到比这更大的问题.

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...