Your syntax for calling the compareTo
method is wrong. Without parentheses ()
, Java interprets it as a class variable. Try
if (compareTo(tim) == 1)
Question
The error i have is
Error:cannot find symbol
symbol: variable compareTo
location:variable tim of type Time
The code where the error happens is
public String difference(Time tim)
{
if(tim.compareTo==1)
{
tim.minute = 0;
}
//other code
}
and my compareTo
is
public int compareTo(Object other)
{
if (((Time)other).getHour()<hour)
{
return 1;
}
//and other code that repeat for return -1 and 0
}
La solution
Your syntax for calling the compareTo
method is wrong. Without parentheses ()
, Java interprets it as a class variable. Try
if (compareTo(tim) == 1)