java Processing 2.0 中的枚举

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13370090/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 12:28:03  来源:igfitidea点击:

Enums in Processing 2.0

javaenumsprocessing

提问by PriestVallon

Thisquestion refers to version 1.2.1 and it doesn't compile at a different part so it's not a duplicate.

这个问题指的是 1.2.1 版,它不会在不同的部分编译,所以它不是重复的。

I want to use enums in Processing. I've read they work better in a separate file so I have done that. This code compiles correctly:

我想在处理中使用枚举。我读过它们在单独的文件中工作得更好,所以我已经这样做了。此代码正确编译:

enum Status
{
    STOPPED,MOVING
};

But when I have this code

但是当我有这个代码时

Status status;

in a different file it gives me the following error:

在另一个文件中,它给了我以下错误:

Unrecognized type:46 (ENUM_DEF)

I know enums aren't supported in earlier versions of Processing but are they supported in version 2.0? If so what's cause the error?

我知道早期版本的 Processing 不支持枚举,但 2.0 版支持它们吗?如果是这样,是什么导致了错误?

回答by spex

When you make a new tab for your enum, are you appending .java? In your case, is your new tab named Status.java?

当您为枚举创建新选项卡时,是否附加了 .java?在您的情况下,您的新选项卡是否名为 Status.java?

Your code compiles fine for me in Processing 2.0b6 with the main tab contents:

您的代码在 Processing 2.0b6 中与主要选项卡内容对我来说编译得很好:

Status status;

And a new tab named Status.java with the contents:

还有一个名为 Status.java 的新选项卡,内容如下:

enum Status
{
    STOPPED,MOVING
};