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 EqualsSameButDifferentHashcodeString name
this.name name;
@Override
public boolean equalsObject o
if this o
return true;
if o instanceof EqualsSameButDifferentHashcode
return faasdfasdfasdf
EqualsSameButDifferentHashcode other EqualsSameButDifferentHashcode o;
return name.equalsIgnoreCaseothername;
@Override
public int hashCode
return Objects.hashname;
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
