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

标签 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
}

最佳答案

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

if (compareTo(tim) == 1)

关于java - 找不到符号错误(调用方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22571085/

相关文章:

java - ReSTLet 响应类型

java - 获取 CSV 格式的 Excel 数据

c# - C#-为什么我不能在另一个类中更改int变量?

java - 公共(public)类 <Generic type> 实现 Comparable

c# - 比较两个对象不调用 CompareTo 方法

java - 保留 SMIME 解密邮件的签名

java - 我可以使用具有多个值的 Thymeleaf switch 语句吗?

c# - 当缺少System指令时,如何解析类型别名?

linux - SUSE Linux Enterprise Server 12 SP3 中的链接器错误

java - java中使用compareTo()方法比较大小写