lundi 28 septembre 2015

Is there a way to automatically initialize a variable if null

I have this code in jsp:

String foo = request.getParameter("bar");
if (foo == null) { 
    foo = ""; 
}

There are multiple values checked this way, now I am by no means an expert on java or jsp but have this code on my table. In other languages I would probably be able to do something like this:

String foo = request.getParameter("bar") || "";

I was really just wondering if there is an equivalent since I have some values which all needs checking so any ideas would be greatly appreciated. (It's really not a big issue, it's mostly just my tidy side preferring not to do multiple lines of checking for null, as it makes the code harder (imo) to read).

thanks in advance.




Aucun commentaire:

Enregistrer un commentaire