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

Correct position of return type?

Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the return position in the following piece od code correct or should it be after the catch block? If i put the return type at the end then i need to create an object for the same.

return ((AgendaServiceEJB) this.ejbSession).getMeetingAgenda(
catch (RemoteException remoteException)
throw new ProblemComunicatingWithEJBException(
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gavi,

Depends on what you mean by "Correct" :
- If you mean, does it work?, then presumably you've tested it and it's doing what you want.
- If you mean is this the best way of laying out the code, then I think the fact that your gut feeling has led you to post here is its own answer

You have one statement doing three things :
- Casting this.ejbSession
- Calling a function
- Doing a return

Generally, you want each statement to do just one thing, so this statement should be split.

First off, why do you need the cast? What type is "this.ejbSession", and could it instead be declared as AgendaServiceEJB? If not, you could always declare a local variable.

So, how about something like :

One last point: You say "you need to create an object". Not true - the code above does not create any more objects than your original. All you've created is a local REFERENCE to the agenda.
Popeye has his spinach. I have this tiny ad:
Garden Master Course kickstarter
    Bookmark Topic Watch Topic
  • New Topic