How to investigate objects/types/etc. from Scala REPL?

前端 未结 4 1805
长发绾君心
长发绾君心 2020-12-22 23:59

I\'ve been working with Scala for a while now and have written a 10,000+ line program with it, but I\'m still confused by some of the inner workings. I came to Scala from Py

4条回答
  •  抹茶落季
    2020-12-23 00:24

    Note that scala 2.11.8 New tab-completion in the Scala REPL can facilitate the type exploration/discovery.

    It now includes:

    • CamelCase completion:
      try:
      (l: List[Int]).rroTAB,
      it expands to:
      (l: List[Int]).reduceRightOption

    • Find members by typing any CamelCased part of the name:
      try:
      classOf[String].typTAB, to get getAnnotationsByType, getComponentType and others

    • Complete bean getters without typing get:
      try:
      (d: java.util.Date).dayTAB

    • Press TAB twice to see the method signature:
      try:
      List(1,2,3).partTAB,
      which completes to:
      List(1,2,3).partition;
      press TAB again to display:
      def partition(p: Int => Boolean): (List[Int], List[Int])

提交回复
热议问题