I would say example #1 is potentially more efficient. Example #2 invokes a method on a object instance twice and this could result in a resource intensive operation occuring twice. Of course, it appears to be a simple getter method and it probably does not do that, but I assume you are asking the question in general.
A benefit of the #2 approach over the #1 approach is that the variable 'formcomments' will not exist in a 'null' state. With #1 someone could come along and interject code between your first and second steps and cause a problem (unlikely of course, but it is a potential issue.) -- Jonathan Rippy -----Original Message----- From: Tony Spencer [mailto:[EMAIL PROTECTED] Sent: Thursday, July 22, 2004 2:18 PM To: 'Research Triangle Java User's Group mailing list.' Subject: [Juglist] RE: Which is more efficient? Sorry. My stupid email client dropped some carriage returns. Example 1: ---------- String formcomments = attr.getFormComments(); formcomments = (formcomments == null) ? "" : formcomments; Example 2: ---------- String formcomments = (attr.getFormComments()== null) ? "" : attr.getFormComments(); T O N Y S P E N C E R Notsleepy LLC 6512 Six Forks Rd. Suite 502-B Raleigh, NC 27615 Phone: 919.848.0691 Mobile: 415.637.6481 [EMAIL PROTECTED] > -----Original Message----- > From: Tony Spencer [mailto:[EMAIL PROTECTED] > Sent: Thursday, July 22, 2004 2:15 PM > To: 'Research Triangle Java User's Group mailing list.' > Subject: Which is more efficient? > > Which of these examples is better practice or does not not > really matter? > > Example 1: > > String formcomments = attr.getFormComments(); formcomments = > (formcomments == null) ? "" : formcomments; > > > Example 2: > String formcomments = (attr.getFormComments()== null) ? "" : > attr.getFormComments(); > > > > T O N Y S P E N C E R > Notsleepy LLC > 6512 Six Forks Rd. > Suite 502-B > Raleigh, NC 27615 > Phone: 919.848.0691 > Mobile: 415.637.6481 > [EMAIL PROTECTED] > > _______________________________________________ Juglist mailing list [EMAIL PROTECTED] http://trijug.org/mailman/listinfo/juglist_trijug.org _______________________________________________ Juglist mailing list [EMAIL PROTECTED] http://trijug.org/mailman/listinfo/juglist_trijug.org
