poh*_*ohl 9 scala tab-completion scala-2.9 read-eval-print-loop
在通过Cay S. Horstmann的"Scala for the Impatient"的过程中,我注意到第一章第一次练习所揭示的一些有趣的东西.
当我这样做时,我得到以下内容
scala> 3. % & * + - / > >= >> >>> ^ asInstanceOf isInstanceOf toByte toChar toDouble toFloat toInt toLong toShort toString unary_+ unary_- unary_~ |
但是我注意到如果我第二次点击Tab,我会得到一个略有不同的列表.
scala> 3. != ## % & * + - / >= >> >>> ^ asInstanceOf equals getClass hashCode isInstanceOf toByte toChar toDouble toFloat toInt toLong toShort toString unary_+ unary_- unary_~ |
REPL试图在这里告诉我什么?第二次出现的不同方法有什么特别之处吗?
Tra*_*own 11
在REPL中按两次选项卡会提高完成的详细程度:
如果"methodName"在
z完成之中,并且verbosity > 0连续两次按下指示选项卡,则我们调用alternativesFor并显示重载方法签名列表.
解释器源中的以下方法指示在方法完成时过滤了什么verbosity == 0(即,当您只打了一次tab而没有获得alternativesFor版本时):
def anyRefMethodsToShow = Set("isInstanceOf", "asInstanceOf", "toString")
def excludeEndsWith: List[String] = Nil
def excludeStartsWith: List[String] = List("<") // <byname>, <repeated>, etc.
def excludeNames: List[String] =
(anyref.methodNames filterNot anyRefMethodsToShow) :+ "_root_"
def exclude(name: String): Boolean = (
(name contains "$") ||
(excludeNames contains name) ||
(excludeEndsWith exists (name endsWith _)) ||
(excludeStartsWith exists (name startsWith _))
)
Run Code Online (Sandbox Code Playgroud)
因此,使用一个选项卡,您可以通过一些规则筛选方法,而解释程序开发人员已经确定这些规则是合理且有用的.两个选项卡为您提供未经过滤的版本.
| 归档时间: |
|
| 查看次数: |
1105 次 |
| 最近记录: |