Fix Java equals() Null Pointer Exception

In Java, the reason why a null pointer exception occurs when calling the equals() method is usually because the parameter passed is null. To solve this issue, you can first check if the parameter passed is null before calling the equals() method. This can be avoided by using the following method:

public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj == null || getClass() != obj.getClass()) {
        return false;
    }
    
    // 进行其他比较逻辑
    
    return true;
}

In the example above, we first check if the incoming obj is null. If it is null, we return false directly to avoid null pointer issues. Then we proceed with other comparison logic to ensure the correctness of the equals() method.

bannerAds