-->

Monday, 9 July 2012

Eating Null Pointer Exceptions and Having The Unabomber

One common cause of a NullPointerException is calling the equals method on a string. For example,
word.equals("word");
If word is null, an exception is thrown. A clever trick to avoid this is to reverse the order of the comparison by calling the following:
"word".equals(word);
Since the string literal "word" is guaranteed to exist, you will not generate an exception.

Second time I have used this clip.

One phrase that people often have trouble with is 'having your cake and eating it to'. - because and can mean simultaneously or occurring in order. In the introduction to one of Carl Zimmer's language column, a reader points out how he was perplexed by the phrase until he reversed the order: you can't eat your cake and have it too. This leaves only one logical meaning.


The distinctive phrasing also helped to catch the Unabomber:
Most notoriously, a young Theodore J. Kaczynski learned from his mother that “you can’t eat your cake and have it too” was the correct way to say it. When Kaczynski later penned an anarchist manifesto in the guise of the Unabomber, the appearance of that particular turn of phrase helped F.B.I. analysts, working with Kaczynski’s brother David, identify who the author was and bring him to justice for his mail-bombing spree.

Arrow Key Nav