scala 包冲突 [英] scala package conflict

查看:55
本文介绍了scala 包冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含根包scala"的库,现在我有一个使用这个库的项目,我有一个名为com.zjffdu.scala"的子包.而这个包中的类文件需要从库中导入类.所以我有以下导入语句.

I have a library which has root package "scala", and now I have a project using this library, and I have a sub package named "com.zjffdu.scala". And the class file in this package needs to import classes from the library. So I have the following import statement.

import scala._

但是因为这个类也在"scala"包中,所以scala编译器会在当前目录而不是库中查找文件.

But because this class is also in package "scala", the scala compiler will look for files in current directory rather than the library.

那么我怎样才能显式地告诉 Scala 从库中导入类.

So how can I explicit to tell scala to import classes from the library.

谢谢

推荐答案

使用这个:

import _root_.scala._

正如你所看到的,它不是很漂亮——最好的选择可能是避免将你的包命名为 scala.

As you can see it's not very pretty — the best option is probably to avoid naming one of your packages scala.

顺便说一下——根 scala 包总是预先导入的(当然子包不是).

And by the way — the root scala package is always preimported (though subpackages, of course, are not).

这篇关于scala 包冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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