2

I wrote a code below in Scala .

object Main {
  def main(args: Array[String]): Unit = {
    println(main) 
  }
}

It gave output as : Main$$$Lambda$3/1543727556@3930015a Why is this value returned ?

Also, When I wrote a simple method like one below :

def wow(): Unit = {
  println(wow)
}

But it gives compilation error.

  • 1
    In 2.13.6 vice versa the former doesn't compile https://scastie.scala-lang.org/qOF01CXXQ4abNIk3YOwraw and the latter does https://scastie.scala-lang.org/Mmwk2kpuR1m6Ki4PvXW2iA It's about transforming a method into a lambda and printing the lambda. – Dmytro Mitin Jul 11 '21 at 08:37
  • I am using Scala3 to compile the code and In IntelliJ IDE. @DmytroMitin But why converted into lambda , and then why only main method ? – Dave Prateek Jul 11 '21 at 08:48
  • Ok, good to know. It's still about transforming a method into a lambda and printing the lambda. There is a difference when there are method parameters and there are no. https://scastie.scala-lang.org/l0qcTOb8TkyvmPEbFJtSrA https://scastie.scala-lang.org/x0rV5Al1SjOqXg6gykND7g – Dmytro Mitin Jul 11 '21 at 08:52
  • Add parameters to `wow` and you'll see https://scastie.scala-lang.org/kg5n08LdShamkTAXIOQ6bg – Dmytro Mitin Jul 11 '21 at 08:54
  • Please see http://dotty.epfl.ch/docs/reference/changed-features/eta-expansion.html – Dmytro Mitin Jul 11 '21 at 08:55
  • Or transform method `wow` into a lambda with explicit underscore https://scastie.scala-lang.org/aSgnFNSxSTOeIslW2ZCkUw – Dmytro Mitin Jul 11 '21 at 09:00

0 Answers0