Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-27323

Use Single-Abstract-Method support in Scala 2.12 to simplify code

    XMLWordPrintableJSON

Details

    Description

      Scala 2.12 supports Single Abstract Method (SAM) syntax like Java 8. Using this would lightly simplify a lot of code where we define an anonymous inner class. E.g.

      private[sql] val ordering = new Ordering[InternalType] {
          override def compare(x: Array[Byte], y: Array[Byte]): Int = {
            TypeUtils.compareBinary(x, y)
          }
        }
      

      becomes:

        private[sql] val ordering = (x: Array[Byte], y: Array[Byte]) => TypeUtils.compareBinary(x, y)
      

      There's a small improvement to readability, and probably a tiny benefit at runtime as these become lambdas in the JVM, not inner classes that have to be compiled and instantiated. (There's also a very small reduction in the chance that those inner classes are accidentally holding references to things we don't want them to.)

      Attachments

        Issue Links

          Activity

            People

              srowen Sean R. Owen
              srowen Sean R. Owen
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: