Javatpoint Logo

Flaws in topic of spring tutorial. (Setter Injection with Non-String Map (having dependent Object) Example)

By: sreeva*** On: Tue Dec 29 02:56:31 IST 2015     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
Topic : Setter Injection with Non-String Map (having dependent Object) Example
==
The topic is explained nicely but there is one very big flaw in the tutorial which needs to be rectified.
In example, class "Answers" is taken as a key of Map but in "Answers" class you must need to override equals(Object o) and hashCode() method and provide the logic to check for Uniqueness of keys ...
in the code this thing is not done due to which Duplicate keys are also getting allowed with the use of Object's class's default hashCode and equals method behavior..

Please rectify this issue.
Like in the code I just added below code to make it logically correct :

In Answer.java below code added...

public boolean equals(Object answers)
{
if(this.id == ((Answer)answers).id)
return true;
else
return false;

}
@Override
public int hashCode()
{
return (new Integer(this.id).hashCode());
}


Up0Down