Frage

Hey guys I am having problems with my hashcode method I wrote. I am trying to add together the hashcode of the variables name and price and return the answer. I keep having the error "Remove Argument to match hashcode()".... My code is provided below. I think the issue is having something to do with me trying to get the hashcode of the price. If someone could lead me to the right direction it would be appreciated. Thanks all!

public int hashcode()
{

 double answer = name.hashcode() + Double.hashcode(new Double(price));
 return (int) answer;

}
War es hilfreich?

Lösung

You want "new Double (price).hashCode()" for the "price" part of the expression.

Andere Tipps

The way you are invoking hashCode on Double class is wrong, hashCode() is a member function & not a static function.

You can use the following :

public int hashCode()
{

  int answer = name.hashCode() + new Double(price).hashCode();
  return answer;

}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top