开发者

Enumeration in Java

I'd like to know what is wrong with my code

public static enum e_option
{
        HELP,
        AUTHOR,
        PROJ_NAME,
        DESC,
        MAIN_CLASS_NAME,
        BASE_DIR,
        XML_NAME,
        RULE_OPT,
        UNKNOWN
}

the i have this method which is

public e_option s2i(String arg)
    {
        e_option opt = null;
        if (a开发者_如何学Crg.equals("--help"))
        {
            opt = HELP;
        }
        if (arg.equals("--author"))
        {
            opt = AUTHOR;
        }

    }

the problem is eclipse doesn't recognize HELP and AUTHOR. It suggest me to create new constants which is bizzare.


To get an enum's value you have to use its name:

opt = e_option.HELP;


Why don't you try e_option.HELP instead of HELP?


You need to specify the enum name:

opt = e_option.HELP;


Among other things, it is wrong that you promise to return an e_option, but you don't do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜