While working my way through Cay S. Horstmann’s “Scala for the Impatient”, I noticed something interesting revealed by the first exercise in the first chapter.
- In the Scala REPL, type 3. followed by the Tab key. What methods can be applied?
When I do this, I get the following
scala> 3. % & * + - / > >= >> >>> ^ asInstanceOf isInstanceOf toByte toChar toDouble toFloat toInt toLong toShort toString unary_+ unary_- unary_~ |
But I noticed that if I hit Tab a second time, I get a slightly different list.
scala> 3. != ## % & * + - / >= >> >>> ^ asInstanceOf equals getClass hashCode isInstanceOf toByte toChar toDouble toFloat toInt toLong toShort toString unary_+ unary_- unary_~ |
What is the REPL trying to tell me here? Is there something special about the different methods that appear the second time?
Hitting tab twice in the REPL raises the verbosity of the completion:
The following methods from the interpreter source indicate what’s filtered for method completion when
verbosity == 0(i.e., when you’ve only hit tab once and aren’t getting thealternativesForversion):So with one tab you’re getting the methods filtered by some rules that the interpreter developers have decided are reasonable and useful. Two tabs gives you the unfiltered version.