color+" square of width "+ width println("Creating " + name) def area = width * width override def toString = name } var sq = new Square(10, "blue") -> Creating blue square of width 10.0 -> sq: Square = blue square of width 10.0 Body is constructor
of package scala.collection import scala.collection._ // Importing all members of object HashSet - similar to static import in java import scala.collection.immutable.HashSet._ Imports
of package scala.collection import scala.collection._ // Importing all members of object HashSet - similar to static import in java import scala.collection.immutable.HashSet._ // Importing Actor and Channel from package scala.actor import scala.actors.{Actor, Channel} Imports
=> JavaBoolean} object Imports{ // We can use JavaBoolean as we would used the Boolean var bool = new JavaBoolean(true) print(bool) } Imports - advanced
=> JavaBoolean} object Imports{ // We can use JavaBoolean as we would used the Boolean var bool = new JavaBoolean(true) print(bool) class SomeInnerClass{ // This import is only visible inside of SomeInnerClass import scala.concurrent.TaskRunners val runner = TaskRunners.threadRunner //... } } Imports - advanced
=> JavaBoolean} object Imports{ // We can use JavaBoolean as we would used the Boolean var bool = new JavaBoolean(true) print(bool) class SomeInnerClass{ // This import is only visible inside of SomeInnerClass import scala.concurrent.TaskRunners val runner = TaskRunners.threadRunner //... } // Imports can be declared anywhere import java.io.File new File("a.txt") } Imports - advanced
}catch{ case x => if (attempts == 1) throw x retry(attempts - 1)(block) } } var content = retry(3){ Source.fromFile("someFile.txt").toString } println(content) New control structures