Is scala import recursive?

2019-02-22 09:23发布

问题:

With

import mypack._

do I still need to

import mypack.box.writer
import mypack.box.reader

and

import mypack.box.parser.stringparser

?

And what's the proper keyword to search/google? "Recursive" gives me overwhelming "tail recursion" results.

回答1:

No, Scala import is not recursive.

Packages are there to keep the namespace in the current scope clean. Importing all subpackages by default would go against that.

On the other hand, imports are relative, so you can do this:

import mypack._
import box.writer
import box.reader
import box.parser.stringparser

Some people dislike this style, as it is somewhat error-prone. I dislike it because there's no clear distinction between absolute and relative imports. Still, it helps sometimes.



标签: scala import