I have a class that has a List of Article (or what you want). Is it safe to implement/override the hashCode()
function in that class like this :
class Place{
List <Article> list = new List<Article>();
public int hashCode() {
if(list.isEmpty())
return 0; //is it safe to return 0
else
return list.get(0).hashCode();
}
}
public class Main{
private HashSet<Place> places = new HashSet<>();
//this function must be donne like this
public boolean isArticleIn(Article article){
Place place = new Place();
place.add(article);
return places.contains(place);
}
}
Is there a possibility to have a list that is not empty and return 0.