instanceof keyword vs. isInstance method
1. instanceof is a reserved word of Java.
isInstance(Object obj) is a method of java.lang.Class.
2. instanceof is used of identify whether the object is type of a particular class or its subclass.
isInstance(obj) is used to identify object of a particular class.
Example
if (obj instanceof MyType) {
...
} else if (MyType.class.isInstance(obj)) {
...
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.