Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dual package statements in Scala

Tags:

package

scala

I have seen in a few libraries, Spray for example, dual package specifications like this:

package cc.spray
package http

// code

Is this just eye candy for package cc.spray.http, or is there a functional benefit to breaking the two apart like this?

like image 294
Greg Avatar asked Jun 15 '12 21:06

Greg


2 Answers

That is equivalent to this:

package cc.spray.http
import cc.spray._
// implicitly, import cc.spray.http._

That is, every member of package cc.spray and of package cc.spray.http are visible. On the other hand, members of the package cc are not visible.

This way one can safely use names such as java in their package hierarchy without causing trouble, and, at the same time, easily make visible the package scopes one wants to be visible.

like image 148
Daniel C. Sobral Avatar answered Sep 19 '22 14:09

Daniel C. Sobral


The separate package statements puts both cc.spray and cc.spray.http in scope.

like image 23
leedm777 Avatar answered Sep 19 '22 14:09

leedm777