Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
和
import mypack._
我还需要吗
import mypack.box.writer import mypack.box.reader
import mypack.box.parser.stringparser
?
什么是搜索/谷歌的正确关键字?“递归”给了我压倒性的“尾递归”结果。
不,Scala 导入不是递归的。
包的存在是为了保持当前范围内的命名空间干净。默认情况下导入所有子包会违背这一点。
另一方面,导入是相对的,所以你可以这样做:
import mypack._ import box.writer import box.reader import box.parser.stringparser
有些人不喜欢这种风格,因为它有点容易出错。我不喜欢它,因为绝对和相对进口之间没有明显的区别。不过,它有时会有所帮助。