menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Stop Crash...
source image

Medium

2d

read

106

img
dot

Stop Crashing Your Java Apps with .equals() – Here's the Right Way to Use It

  • Calling .equals() on a variable that hasn’t been initialized can lead to a NullPointerException.
  • Flipping the order of the comparison can prevent a crash when using .equals().
  • Using a constant string with .equals() ensures the method call works safely.
  • The method .equals() belongs to the object on which it is called.
  • Calling null.equals() will result in a crash, while "hello".equals(null) returns false.
  • Understanding this can provide extra safety, particularly in critical applications.

Read Full Article

like

6 Likes

For uninterrupted reading, download the app