continue - Java String initialization (part 2) -


i asked this goofy question earlier today , got answers. think meant ask following:

string astring = ""; // or = null ? if(somecondition)    astring = "something";  return astring; 

in case, string has initialized in order return it. thought either option (setting "" or null looks kind of ugly. wondering others here...or more of matter of whether want empty string or null being passed around in program (and if prepared handle either)?

also assume intermediary logic long cleanly use conditional (? :) operator.

depends on want achieve,

in general return null signal nothing processed, might later pop cases somecondition true string build "" anyway, way can differentiate case if return null if nothing processed.

i.e.

string astring = null; if(somecondition)   astring = "something";  return astring; 

but depends on want achieve... e.g. if code suppose build string delivered directly in ui go "" instead


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -