Characteristics
Scala's trait can be implemented in a way that compares to Java's interface. Scala's trait supports the blending of classes and singleton objects with multiple trait (using methods from these trait, without violating the principle of single inheritance).
Scala defines an app trait type for the Singleton object's main, so the above example can be simplified to:
Helloworld.scalaobject HelloWorld extends App {println ("Hello world!");}
This code cannot be run as a script, and Scala's script requires that the code end with an expression. So to run this code, you need to compile the code before you run it.
Run directly for the first time without any output G:\hadoop\scala-sdk\source>scala helloworld.scala//to compile G:\hadoop\scala-sdk\source>scalac helloworld.scala//run G:\hadoop\scala-sdk\source>scala Helloworldhello world! again
Note: Scala provides a quick-compile code for the Auxiliary command FSC (Fast Scala Compliler), which uses this command to start the JVM only the first time the FSC is used, and then the FSC runs in the background, thus avoiding the need to load the associated library file every time the Scalac is used. Thus increasing the speed of compilation.
Multiple inheritance
Trait use
Trait structure
Specialty Applications
This article is from the "Ruchunli's work Notes" blog, so be sure to keep this source http://luchunli.blog.51cto.com/2368057/1705025
Scala2.11.7 Study Notes (vi) Introduction to Scala traits