Eclipse自动完成无法正常工作

时间:2014-08-09 02:20:31

标签: java eclipse

基本上,我有这样的情况:

enter image description here

我想知道为什么自动完成功能不会显示变量lineItems

我在Eclipse Kepler上使用Mac OS并按Control + Space

编辑:

我看过类似的问题,我相信我已正确设置首选项。

enter image description here

2 个答案:

答案 0 :(得分:3)

因为 non-static variables can not be referenced from static context eclipse 比我们想象的更智能只是将static关键字添加到您的列表中,它会显示建议。

即使你自己写完全名仍然没有用,因为它会给你错误,从配置我认为你会得到其他功能的建议。

答案 1 :(得分:2)

创建TreeFormatter的实例,或使实例变量为静态。

import java.util.LinkedList;
import java.util.List;


public class TreeFormatter {

List<String> lineItems = new LinkedList<String>();

static List<String> staticlineItems = new LinkedList<String>();

public static void main(String[] args) {

    // make an instance of TreeFormatter
    TreeFormatter tf = new TreeFormatter();
    tf.lineItems.add("foo");

    // or make it static
    staticlineItems.add("bar");

}
}