== operator for object in Java

Salad Lam - Jan 31 - - Dev Community

Notice

I wrote this article and was originally published on Qiita on 31 August 2021.


In past I don't understand why code in inner block doesn't run.

if (new Integer(1) == new Integer(1)) {
  doImportantJob();
};
Enter fullscreen mode Exit fullscreen mode

Since "==" operator for object means if both objects point to the same memory location. The code above means two Integer(1) object is created, of course two sides must point to different memory location.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player