Since a value in quotes is really a String object, you can call methods like .equals() on it, as follows:


if (userName != null && userName.equals("Fred")) ...

// could be written as follows:

if ("Fred".equals(userName)) ...

If you cram too much cleverness into one line the code will quickly become unreadable, as in the following real world example:


dlLocal = !"false".equals(processing.getConfig().getProperty(DOWNLOAD_LOCAL_SETTING));

blog comments powered by Disqus