我有一个对象,我想检测什么类型,所以我可以打电话
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);
RelationalExpression
instanceof
ReferenceTypeAt run time,the result of the
instanceof
operator istrue
if the value of the RelationalExpression is notnull
and the reference Could be cast (§15.16) to the ReferenceType without raising aClassCastException
. Otherwise the result isfalse
.
看看你的使用模式,但是,看起来你可能会遇到比这更大的问题.
原文地址:https://www.jb51.cc/java/125870.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。