Difference between asInstanceOf[ ] and isInstanceOf[ ] in scala -
what difference between asinstanceof[] , isinstanceof[]?
generally speaking, a.asinstanceof[b] performs actual cast: takes object of type , returns (if possible) object of type b, whereas a.isinstanceof[b] returns boolean indicating whether a has type b or not.
strictly speaking isinstanceof[b] looks not if of type b, if has type b in upper side inheritance tree (so if b superclass of a, isinstanceof yield true) , important notice isinstanceof works on actual object type hierarchy rather on reference type.
Comments
Post a Comment