【发布时间】:2014-09-18 21:58:44
【问题描述】:
private List<String> tokens = new ArrayList<String>();
我有一些代码,但这给了我一个错误。
我使用 Eclipse,它在 字符下方显示了一个红色下划线。我不知道为什么。一切似乎都很好。这是整个代码:
public class Analyze {
protected String text = null;
public List<String> tokens = new ArrayList<String>(); // Error is right here.
this.tokenize();
public Analyze(String txt) {
// This is the constructor. I will call the class outside with a variable just like method. Just like: Analyze aText = new Analyze("Some texts here.");
// Then I will call the tokens variable inside the class. (Or am I just doing it wrong?)
this.text = txt;
}
private List<String> tokenize() {
// Some codes that changes the value of "tokens" variable.
}
}
我在网上和这个平台上看了一下,我一般发现一些逻辑运算符如 、= 等会导致这个问题,但不是 ;。
其他编辑
当我像这样更改这些行的位置时:
public List<String> tokens = new ArrayList<String>();
protected String text = null; // Then error seems right here.
【问题讨论】:
-
this.Analyze();这是无效行
-
正确。那条线需要在某种方法中。另外,你的意思是在那里发生?该方法返回一个值,但您不使用它做任何事情。
-
// Some Codes 区域改变私有tokens变量的值并返回。 (其实我只是看到看起来很傻,我会编辑代码。)
标签: java eclipse assignment-operator