A finder method is defined in the remote home interface, which returns remote interface type. After getting the remote interface type, do i need to do narrowing or type casting to use the object or not...
No, you don't need to do anything if the return type is of the Remote interface type. Just assign it to that Remote interface type in your client. Just think of it as you would any other method... the declared return type is all you need to worry about.
With the Home, of course, the return type of the JNDI lookup method is NOT the Home interface type, so you must cast it. And because it must be IIOP-compliant, you must ALSO do the narrow to *force* it to be the correct object type.
But you must use narrowing ONLY when you are getting something back that is not declared with the exact interface type that you need.
With the EJB home and component interfaces, you'll never have a scenario in which you must do narrowing but not casting--if it's a *stub* coming back from a method, and the declared return type is NOT the Remote interface for that stub, then you must do both a cast and a narrow.
You *could* have a situation, however, where you must do a cast but NOT a narrow--this is true when multiple entity finders. They are coming in as a Collection, but we know that (assuming the bean was built correctly) the Right Thing (i.e. the component interface type) is IN the Collection. So we still have to cast, of course, as we would with *anything* in a Collection that we want to assign to something other than Object, but we do not have to do a narrow... we can simply trust that the right thing was indeed placed into the Collection.
My, my, aren't you a big fella. Here, have a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!