Which of those calls is the most efficient?
1 posts in topic
Flat View  Flat View

Posted By:   joey_corleon
Posted On:   Thursday, October 10, 2002 11:07 AM

Look at the following calls:

String pseudo = memberInfo.getSPseudo();
INSERTObj.put( "login", pseudo );
INSERTObj.put( "alias", pseudo );


INSERTObj.put( "login", memberInfo.getSPseudo() );
INSERTObj.put( "alias", memberInfo.getSPseudo() );

Which one is the most efficient - does java compiler manage with them in such way that there is no different at all?

Re: Which of those calls is the most efficient?

Posted By:   Christopher_Koenigsberg  
Posted On:   Thursday, October 10, 2002 02:19 PM

Well, can the memberInfo object change underneath, between 2 successive calls to its getSPseudo(), so that they might return different values? Could the 2nd one throw an exception, return null etc., even if the 1st call succeeds? Is it an expensive operation each time (involving RMI to EJB's indirectly, or JDBC to DBMS, etc.)? I don't think the compiler is going to decide this for you, when just compiling this particular class ...

Also (say yes :-) does this code need to be robust, and therefore check that memberInfo is not null first, next check that the returned pseudo is not null, before finally proceeding with the INSERTObj calls?

About | Sitemap | Contact