【发布时间】:2011-12-17 17:55:31
【问题描述】:
我在 Eclipse 中有一个多项目 Scala 工作区。我认为我对 Scala 导入包的方式缺乏了解而感到厌烦,但是在花费了比我愿意承认的更多时间寻找解决方案之后,我无法弄清楚这一点。我在一个简单的 2 项目设置中重现了这个问题。
项目 1:com.foo.mathematics 包含一个简单的 Vector 类
包含一个文件:
package com.foo.mathematics
class Vector2D(x : Double, y : Double) {
def length = math.sqrt(x*x + y*y)
}
项目 2:com.foo.analysis
package com.foo.analysis
import com.foo.mathematics.Vector2D
class Frame(xAxis : Vector2D, yAxis : Vector2D) {
}
Eclipse 在导入行显示错误,我得到的错误消息是:对象数学不是包 com.foo 的成员。
在大纲视图中,我的导入语句是这样说的:
com.foo.analysis.<error: <none>>.Vector2D
我已尝试将导入更改为:
import mathematics.Vector2D
import _root_.com.foo.mathematics.Vector2D
两者都不起作用...
我错过了什么?
【问题讨论】:
-
尝试清理所有项目。构建项目1,然后在项目2中,删除导入行,然后尝试输入
import com.fo[CTRL-SPACE],完成了吗?如果是,则再次输入 CTRL-SPACE,它是否提供mathmatics和analysis? -
我设法用粗暴的 root 用法修复了它。
标签: eclipse scala import package