Question: I have the following class: public class EqualsSameButDifferentHashcode { private final String name; public EqualsSameButDifferentHashcode ( String name ) { this.name = name; } @Override

I have the following class:
public class EqualsSameButDifferentHashcode {
private final String name;
public EqualsSameButDifferentHashcode(String name){
this.name = name;
}
@Override
public boolean equals(Object o){
if (this == o){
return true;
}
if (!(o instanceof EqualsSameButDifferentHashcode)){
return faasdfasdfasdf}
EqualsSameButDifferentHashcode other =(EqualsSameButDifferentHashcode) o;
return name.equalsIgnoreCase(other.name);
}
@Override
public int hashCode(){
return Objects.hash(name);
}
}
In the overriden equals method, is it ok to use equalsIgnoreCase or just equals when comparing String field values? What are the pros and cons of that? Please provide a sample code to show the benefits and possible issues.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!