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
Post a Comment