gpt4 book ai didi

java - 调用枚举的方法

转载 作者:搜寻专家 更新时间:2023-10-30 19:57:44 24 4
gpt4 key购买 nike

<分区>

我有以下枚举:

 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 修饰符的方法,它将正常工作。为什么?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com