質問

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