4

I know that in Scala you can alias things inside package like that: import some.package.{someObject => someAlias}

Is there a way of creating alias for package name, not for classes/objects inside it ?

For example in Python you can do: import package as alias

Michal Fudala
  • 340
  • 2
  • 10

2 Answers2

9

You can alias a package name the same way you alias an object.

import scala.collection.{mutable => m}

val buffer = m.ListBuffer(1, 2, 3, 4)

buffer: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2, 3, 4)

Fun fact: You can also alias object methods this way.

import scala.collection.mutable.ListBuffer.{apply => makeBuffer}

scala> makeBuffer(1, 2, 3, 4)
res5: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2, 3, 4)
Michael Zajac
  • 55,144
  • 7
  • 113
  • 138
1
import org.joda.time.{DateTime => joda}

Now you can use joda as synonym for DateTime

joda.parse("2014-12-23")
Diego Martinoia
  • 4,592
  • 1
  • 17
  • 36