Check whether the given object is any subtype of Message or is a specific
Message by passing the type.
Just like instanceof, isMessage narrows the type. The advantage of
isMessage is that it compares identity by the message type name, not by
class identity. This makes it robust against the dual package hazard and
similar situations, where the same message is duplicated.
This function is mostly equivalent to the instanceof operator. For
example, isMessage(foo, MyMessage) is the same as foo instanceof MyMessage,
and isMessage(foo) is the same as foo instanceof Message. In most cases,
isMessage should be preferred over instanceof.
However, due to the fact that isMessage does not use class identity, there
are subtle differences between this function and instanceof. Notably,
calling isMessage on an explicit type of Message will return false.
Check whether the given object is any subtype of Message or is a specific Message by passing the type.
Just like
instanceof,isMessagenarrows the type. The advantage ofisMessageis that it compares identity by the message type name, not by class identity. This makes it robust against the dual package hazard and similar situations, where the same message is duplicated.This function is mostly equivalent to the
instanceofoperator. For example,isMessage(foo, MyMessage)is the same asfoo instanceof MyMessage, andisMessage(foo)is the same asfoo instanceof Message. In most cases,isMessageshould be preferred overinstanceof.However, due to the fact that
isMessagedoes not use class identity, there are subtle differences between this function andinstanceof. Notably, callingisMessageon an explicit type of Message will return false.