Scala's operational characteristics are the same as Java's. The Scala compiler generates byte code that is nearly identical to that generated by the Java compiler.[15] In fact, Scala code can be decompiled to readable Java code, with the exception of certain constructor operations. To the Java virtual machine (JVM), Scala code and Java code are indistinguishable. The only difference is one extra runtime library, scala-library.jar.[30]
Functional programming languages commonly provide tail call optimization to allow for extensive use of recursion without stack overflow problems. Limitations in Java bytecode complicate tail call optimization on the JVM. In general, a function that calls itself with a tail call can be optimized, but mutually recursive functions cannot. Trampolines have been suggested as a workaround.[36] Trampoline support has been provided by the Scala library with the object scala.util.control.TailCalls since Scala 2.8.0 (released 14 July 2010). A function may optionally be annotated with @tailrec, in which case it will not compile unless it is tail recursive.[37]
Scala projects need to declare a scala-library dependency. This dependency will then be used on compile and runtime class paths. It will also be used to get hold of the Scala compiler and Scaladoc tool, respectively.[1]
The ScalaCompile and ScalaDoc tasks consume Scala code in two ways: on their classpath, and on their scalaClasspath. The former is used to locate classes referenced by the source code, and will typically contain scala-library along with other libraries. The latter is used to load and execute the Scala compiler and Scaladoc tool, respectively, and should only contain the scala-compiler library and its dependencies.
The Zinc compiler itself needs a compatible version of scala-library that may be different from the version required by your application.Gradle takes care of specifying a compatible version of scala-library for you.
The source directories containing the Scala source files of this source set. May also contain Java source files for joint compilation.Can set using anything described in Understanding implicit conversion to file collections.Default value: [projectDir/src/name/scala].
The Zinc-based Scala Compiler supports joint compilation of Java and Scala code. By default, all Java and Scala code under src/main/scala will participate in joint compilation. Even Java code will be compiled incrementally.
Incremental compilation requires dependency analysis of the source code. The results of this analysis are stored in the file designated by scalaCompileOptions.incrementalOptions.analysisFile (which has a sensible default). In a multi-project build, analysis files are passed on to downstream ScalaCompile tasks to enable incremental compilation across project boundaries. For ScalaCompile tasks added by the Scala plugin, no configuration is necessary to make this work. For other ScalaCompile tasks that you might add, the property scalaCompileOptions.incrementalOptions.publishedCode needs to be configured to point to the classes folder or Jar archive by which the code is passed on to compile class paths of downstream ScalaCompile tasks. Note that if publishedCode is not set correctly, downstream tasks may not recompile code affected by upstream changes, leading to incorrect compilation results.
You can learn more elsewhere:
The optimizer removes unnecessary loads of certain built-in modules, for example scala.Predef and scala.runtime.ScalaRunTime. This means that initialization (construction) of these modules can be skipped or delayed.
What? No solution to the exercises? I am not putting them up because many readers enjoy working them out themselves. If you google for "horstmann scala impatient solutions", you'll find blogs and github sites of fellow readers that might (give you inspirationspoil the fun).
I am amazed by the effort undertaken by the authors of Programming inScala. This book is an invaluable guide to what I like to call Scalathe Platform: a vehicle to better coding, a constant inspiration forscalable software design and implementation. If only I had Scala in itspresent mature state and this book on my desk back in 2003, whenco-designing and implementing parts of the Athens 2004 Olympic GamesPortal infrastructure!
To get started with a worksheet you can either use the metals.new-scala-filecommand and select Worksheet or create a file called *.worksheet.sc. Thisformat is important since this is what tells Metals that it's meant to betreated as a worksheet and not just a Scala script. Where you create the scriptalso matters. If you'd like to use classes and values from your project, youneed to make sure the worksheet is created inside of your sources next to anyexisting Scala files. directory. You can still create a worksheet in otherplaces, but you will only have access to the standard library and yourdependencies.
Since Metals v0.11.7 it's now possible to run scalafix rules using a specialcommand metals.scalafix-run. In VS Code can be also run using the defaultshortcut of shift + alt + ctrl + o. This should run all the rules defined inyour .scalafix.conf file. All built-in rules and thecommunity hygiene onescan be run without any additional settings. However, for all the other rulesusers need to add an additional dependency in themetals.scalafixRulesDependencies user setting. Those rules need to be in formof strings such as com.github.liancheng::organize-imports:0.6.0, which followsthe same convention as coursier dependencies.
df19127ead