Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Can i use the return values of finder method directly

Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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,
Cowgirl and Author
Posts: 1589
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

What are you doing in my house? Get 'em tiny ad!
Garden Master Course kickstarter
    Bookmark Topic Watch Topic
  • New Topic