Compare two objects with a check for null

前端 未结 7 1157
鱼传尺愫
鱼传尺愫 2020-12-10 00:21

Is there a method in the JDK that compares two objects for equality, accounting for nulls? Something like this:

public static boolean equals(Object o1, Obje         


        
相关标签:
7条回答
  • 2020-12-10 01:17

    Whenever I come across a need and think "this is so common Java must have it" but find it doesn't, I check the Jakarta Commons project. It almost always has it. A quick search of the commons-lang API (which has the most basic of common utilities) shows an equals() method that provides what you want.

    0 讨论(0)
提交回复
热议问题