Java – what does “multiple tags” mean?

I try to use collections in the following ways:

static Set<String> languages = new HashSet<String>();
languages.add("en");
languages.add("de");

I received the following error message generated by Eclipse:

> Multiple markers at this line
>   - Syntax error on token ""en"",delete this      token
>   - Syntax error on token(s),misplaced    construct(s)

I can't figure out what I did wrong Can someone help me?

Solution

"Multiple markers" just means "there is more than one thing in this line"

But the basic problem is that you try to insert statements directly into classes instead of putting them in constructors, methods, initializers, etc

I suggest you change the code to:

static Set<String> languages = getDefaultLanguages();

private static Set<String> getDefaultLanguages()
{
    Set<String> ret = new HashSet<String>();
    ret.add("en");
    ret.add("de");
    return ret;
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>