Compare two objects with a check for null

前端 未结 7 1249
鱼传尺愫
鱼传尺愫 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:00

    Java 7.0 added a new handy class: Objects.

    It has a method exactly for this: Objects.equals(Object a, Object b)

提交回复
热议问题