scala导入是递归的吗? [英] Is scala import recursive?

查看:84
本文介绍了scala导入是递归的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

import mypack._

我还需要

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

import mypack.box.parser.stringparser

搜索/谷歌的关键词是什么? Recursive给了我压倒性的尾递归结果。

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

推荐答案

不,Scala导入不是递归的。

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导入是递归的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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