-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
  • 15,514
  • 17
  • 42
  • 51

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
  • 10,803
  • 7
  • 33
  • 58