Scala: Packages Cheat Sheet

Declaration of Package

package package_name
// Scala classes
// traits
// objects..

Chained methods

package x.y.z
// members of z

Or

package x
package y
package z
// member of z

Nesting packages

package x{
   // members of x {as required}
   package y{
      // members of y{as required}
      package z{
         // members of z{as required}
      }
   }
}

Adding Members to Packages

// file named as faculty.scala
package college
class faculty{
   def faculymethod(){}
}

Wildcard import

import scala.collection._

Selective import

import scala.collection.Vector

Or

import scala.collection.{Vector, Sequence}

Renaming import

import scala.collection.{Vector => Vec14}

Import all from java.util except Date

import java.util.{Date => _, _}

Leave a Reply

Your email address will not be published. Required fields are marked *