java - of advantages of setting the reference variable of runner to the knockOut before the values to the runner variable are set -


in below example, variable runner being set knockout object before values variable runner set. advantages on setting variables object before setting values following variable? appreciated.

would there difference in code 1 , code 2?

code 1

runner = new runner(); knockout.setrunner(runner); if(fpmlmap.get(abcconstants.knock_out_event) != null      && fpmlmap.get(abcconstants.knock_out_event).trim().length() > 0) {      string  knockoutevent = fpmlmap.get(abcconstants.knock_out_event);     runnertypeenum = null;     runner.setrunnertype(runnertypeenum.fromvalue(knockoutevent)); } 

code 2

runner = new runner();     if(fpmlmap.get(abcconstants.knock_out_event) != null      && fpmlmap.get(abcconstants.knock_out_event).trim().length() > 0) {      string  knockoutevent = fpmlmap.get(abcconstants.knock_out_event);     runnertypeenum = null;     runner.setrunnertype(runnertypeenum.fromvalue(knockoutevent)); } knockout.setrunner(runner); 

this way, knockout has reference runner, regardless of outcome of following if block.

edit

to respond edit: there no difference between 2 examples. both ways valid , produce same behavior.

(that's assuming code above "normal" , reasonable programmer expect do.)

you might choose first style improve readability of code, when taken in context. however, second style more common in experience.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -