Does Java also test the equality of handling null values?

Is there anywhere in the Java standard library with static equality functions?

public static <T> boolean equals(T a,T b)
{
    if (a == null)
        return b == null;
    else if (b == null)
        return false;
    else
        return a.equals(b);
}

I have just implemented this in a new project util class, countless times It seems incredible that it will not be published as a standard library function

Solution

There are objects#equals() in JDK 7 From Javadoc:

In addition to the functions mentioned in Apache commons Lang, there is another function in Google guava, objects#equal():

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>