Java哈希代码方法错误

Java哈希代码方法错误,java,hash,hashcode,Java,Hash,Hashcode,嘿,伙计们,我写的hashcode方法有问题。我试图将变量name和price的hashcode相加,并返回答案。我一直出现错误“删除参数以匹配hashcode()”。。。。下面提供了我的代码。我认为问题与我试图获取价格的哈希代码有关。如果有人能把我引向正确的方向,我将不胜感激。谢谢大家 public int hashcode() { double answer = name.hashcode() + Double.hashcode(new Double(price)); return (

嘿,伙计们,我写的hashcode方法有问题。我试图将变量name和price的hashcode相加,并返回答案。我一直出现错误“删除参数以匹配hashcode()”。。。。下面提供了我的代码。我认为问题与我试图获取价格的哈希代码有关。如果有人能把我引向正确的方向,我将不胜感激。谢谢大家

public int hashcode()
{

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

}

表达式的“price”部分需要“new Double(price).hashCode()”。

表达式的“price”部分需要“new Double(price).hashCode()”。

Double
类上调用
hashCode
的方式是错误的,
hashCode()
是一个成员函数,而不是静态函数

您可以使用以下选项:

public int hashCode()
{

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

}

Double
类上调用
hashCode
的方式是错误的,
hashCode()
是一个成员函数,而不是一个静态函数

您可以使用以下选项:

public int hashCode()
{

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

}