Is scala import recursive?

后端 未结 1 1358
时光取名叫无心
时光取名叫无心 2021-01-19 00:02

With

import mypack._

do I still need to

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

and

         


        
相关标签:
1条回答
  • 2021-01-19 00:47

    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.

    0 讨论(0)
提交回复
热议问题