OK, I’ll bite. Why can’t you just do a plain old cast?
According to the spec, you—the client—must assume that the server is using RMI-IIOP rather than regular old RMI. Normal RMI uses JRMP as the wire protocol, which assumes that we’re always talking Java all the way down. If this were plain RMI, you’d always know that what you get out of the lookup is (polymorphically) something that IS-A home interface. In other words, an object whose class type implements the home interface for that bean. And for that scenario, a normal Java language cast would let you assign the object back to the home interface type, so that you can call the home methods! Otherwise, remember, you’d be stuck calling only methods of type Object (equals(), hashCode(), toString(), etc.) when what you really want to call is create().
But when the wire protocol is IIOP, the rules change a little. The narrow() operation gives you something that is castable.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access