作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
<分区>
我有以下枚举:
enum Days{
TODAY{
@Override
public Date getLowerBound(){
another(); //1
currentUpperBound(); //2
return null;
}
@Override
public Date another() {
return null;
}
};
public abstract Date getLowerBound();
public abstract Date another();
private Date currentUpperBound(){
return null;
}
}
为什么 //2
会导致编译时错误
Cannot make a static reference to the non-static method
currentUpperBound() from the type Days
但是 //1
编译正常吗?这两种方法都是非静态的。我看不出有什么问题...也许它与 Eclipse 有关?
更新: 正如@Florian Schaetz 在评论中注意到的那样,如果我们声明具有 static private
修饰符的方法,它将正常工作。为什么?
我是一名优秀的程序员,十分优秀!