-1

What does this ever mean in the block.

if (this == null) {
    // some code
}
else {
    // ...
}

My concern is will this == null ever be true? The Java compiler does not show any error.

Tom
  • 16,842
  • 17
  • 45
  • 54

2 Answers2

1

this == null will never be true. The Java compiler will indeed let you do a few things such as that that have no real purpose, such as if (1==2) {} or throw null;

Daniel O
  • 336
  • 2
  • 3
  • 8
0

this == null always evaluates to false in Java

Alexey Subach
  • 11,903
  • 7
  • 34
  • 60