I've learned that inside a non-static block, this
represents the current reference on which that block is invoked. My doubt is is there any need of checking this
is ever null
or not, I mean if it is null in the first place the block(method, constructor, etc) won't be executed (NPE
). I came across this code where it checks this != null
. It don't know why it is used, is there actually a need?
public int compareTo(StudentMarksTO arg0) {
if(arg0.isIsfalsegenerated()==true) {
if(arg0!=null && this!=null &&
arg0.getFalseNo()!=null && this.getFalseNo()!=null &&
!arg0.getFalseNo().toString().equals("") &&
!this.getFalseNo().toString().equals("") ) {
return this.getFalseNo().compareTo(arg0.getFalseNo());
}
else
return 0;
}
}