“多重标记"有什么作用?意思是? [英] What does the "Multiple markers" mean?

查看:12
本文介绍了“多重标记"有什么作用?意思是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以下列方式使用集合:

I am trying to use sets in the following way:

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

我收到 Eclipse 生成的以下错误消息:

And I get 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 cannot figure out what I am doing wrong. Can anybody please help me?

推荐答案

多个标记"只是意味着这一行有不止一个问题".

"Multiple markers" just means "there's more than one thing wrong with this line".

但基本的问题是您试图将语句直接插入到类中,而不是将它们放在构造函数、方法、初始化程序等中.

But the basic problem is that you're trying to insert statements directly into a class, rather than having them in a constructor, method, initializer etc.

我建议你把代码改成这样:

I suggest you change your code to something like this:

static Set<String> languages = getDefaultLanguages();

private static Set<String> getDefaultLanguages()
{
    Set<String> ret = new HashSet<String>();
    ret.add("en");
    ret.add("de");
    return ret;
}

这篇关于“多重标记"有什么作用?意思是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆