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;

}
有帮助吗?

解决方案

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

其他提示

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;

}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top