8

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._

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

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

Thanks

zjffdu
  • 25,496
  • 45
  • 109
  • 159

1 Answers1

19

Use this:

import _root_.scala._

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

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

Jean-Philippe Pellet
  • 59,296
  • 21
  • 173
  • 234
  • I wish I could award bonus points for not only answering the question, but *gently* advising how to avoid the problem in the first place without coming across as a condescending jerk. +1 – absmiths Feb 28 '18 at 16:15