This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.