找不到符号错误(调用方法)

时间:2014-03-21 23:07:35

标签: java compiler-errors compareto

我遇到的错误是

Error:cannot find symbol
  symbol:  variable compareTo
  location:variable tim of type Time

发生错误的代码是

public String difference(Time tim)
{
      if(tim.compareTo==1)
{
      tim.minute = 0;
}
      //other code
}

我的compareTo

public int compareTo(Object other)
{
    if (((Time)other).getHour()<hour)
    {
     return 1;
    }
 //and other code that repeat for return -1 and 0
}

1 个答案:

答案 0 :(得分:3)

调用compareTo方法的语法错误。如果没有括号(),Java会将其解释为类变量。尝试

if (compareTo(tim) == 1)