我遇到的错误是
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
}
答案 0 :(得分:3)
调用compareTo
方法的语法错误。如果没有括号()
,Java会将其解释为类变量。尝试
if (compareTo(tim) == 1)