سؤال

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
}
هل كانت مفيدة؟

المحلول

Your syntax for calling the compareTo method is wrong. Without parentheses (), Java interprets it as a class variable. Try

if (compareTo(tim) == 1)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top