I have the following funtion that checks if a List of codigos contains a single codigos object:
if (!concorrente.getJcodigoses().contains(cod)) { return "redirect:"+ referrer; }
I read that i need to Override the equals method like so:
@Override public boolean equals(Object object) { boolean isEqual= false; if (object != null && object instanceof Jcodigos) { isEqual = (this.id == ((Jcodigos) object).id); } return isEqual; }
I placed it in my Jcodigos.java class and i noticed that concorrente.getJcodigoses().contains(... never gets into my custom equals method...
Any advice?
Thanks
Answer:
I was missing the following method
@Overridepublic int hashCode() { return this.id;}