Question

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;

}
Was it helpful?

Solution

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

OTHER TIPS

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;

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top