Forums Register Login

Can i use the return values of finder method directly

+Pie Number of slices to send: Send
Hi,

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...

Thanks in Advance,
+Pie Number of slices to send: Send
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.

cheers,
Kathy
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 849 times.
Similar Threads
findByPrimaryKey
Entity-Home interface-finder exception
choosing between home business methods and finders
EJB HELP
Finder method returns collection ...
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:33:13.