Saw this line in a class method and my first reaction was to ridicule the developer that wrote it.. But then, I figured I should make sure I was right first.
public void dataViewActivated(DataViewEvent e) {
if (this != null)
// Do some work
}
Will that line ever evaluate to false?
No it can’t. If you’re using
this, then you’re in the instance sothisisn’t null.The JLS says :
If you invoked a method from an object, then the object exists or you would have a
NullPointerExceptionbefore (or it’s a static method but then, you can’t usethisin it).Resources :
thiskeyword