【发布时间】:2015-05-02 19:59:50
【问题描述】:
因为 Eclipse IDE“这么说”,我对这 2 个小错误感到有些苦恼。我会指出错误。老实说,我不知道如何深入解释这些错误。我认为它们很简单,我无法消除错误。
ScheduledExecutorService timer = Executors.newScheduledThreadPool (1);
timer.scheduleAtFixedRate(new Runnable()
{
public void run()
{
if (lists. size ()> 0)
{
boolean lighted = Lamp.valueOf(Road.this.name).isLighted(); //According to Eclipse, "The method valueOf(Class<T>, String) in the type Enum<Lamp> is not applicable for the arguments (String)"
if (lighted)
{
System.out.println(lists.remove(0) + "is traversing!");
}
}
}
}, 1,1, TimeUnit. SECONDS);
我的包中的另一个错误
public Lamp Blackout()
{
this.lighted = false;
if (opposite != null)
{
Lamp.valueOf(opposite).in.Blackout(); //in cannot be resolved or is not a field. It suggests me to create enum constant, which I did and it wouldn't work either.
}
Lamp nextLamp = null;
if (next != null)
{
nextLamp = Lamp.valueOf(next);
System.out.println("Green" + name () + "--------> switch to" + next);
nextLamp.light();
}
return nextLamp;
}
【问题讨论】:
-
我们需要查看简短但完整的代码示例,让我们重现这些问题。但通常不会显示错误因为 Eclipse IDE“这么说”。而是因为代码中存在问题。
标签: java methods enums value-of