I have an object and I want to detect what type is, so I can call
if (obj isa Integer)
put(key,integerval);
if (obj isa String)
put(key,stringval);
if (obj isa Boolean)
put(key,booleanval);
You're pretty close, actually!
if (obj instanceof Integer)
put(key,integerval);
if (obj instanceof String)
put(key,stringval);
if (obj instanceof Boolean)
put(key,booleanval);
From the JLS 15.20.2:
RelationalExpression
instanceofReferenceTypeAt run time, the result of the
instanceofoperator istrueif the value of the RelationalExpression is notnulland the reference could be cast (§15.16) to the ReferenceType without raising aClassCastException. Otherwise the result isfalse.
Looking at your usage pattern, though, it looks like you may have bigger issues than this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With