Domanda

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;

}
È stato utile?

Soluzione

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

Altri suggerimenti

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;

}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top