Alternative declaration of a package object: object `package`

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Alternative declaration of a package object: object `package`

Jason Zaugg
The "Package Objects" guide [1] shows two ways to declare package objects:

p1/p2/package.scala:

  package object p2

p1/p3/package.scala:

  package p3

  object `package`

I was only aware of the first method -- it is described in the spec;
used in the standard library; and supported in IntelliJ. Is the second
method officially supported, or is it just intended as an illustration
of how package objects are represented?

Perhaps the documentation, or better, the compiler, could make it
clearer which variant to choose.

-jason

[1] http://www.scala-lang.org/docu/files/packageobjects/packageobjects.html#
Reply | Threaded
Open this post in threaded view
|

Re: Alternative declaration of a package object: object `package`

Arya Irani
Are there any use cases / good practices involving package objects?  Should I use them to replace mypkg.Util ?  Etc.

-Arya

On Jan 15, 2011, at 4:51 AM, Jason Zaugg <[hidden email]> wrote:

> The "Package Objects" guide [1] shows two ways to declare package objects:
>
> p1/p2/package.scala:
>
>  package object p2
>
> p1/p3/package.scala:
>
>  package p3
>
>  object `package`
>
> I was only aware of the first method -- it is described in the spec;
> used in the standard library; and supported in IntelliJ. Is the second
> method officially supported, or is it just intended as an illustration
> of how package objects are represented?
>
> Perhaps the documentation, or better, the compiler, could make it
> clearer which variant to choose.
>
> -jason
>
> [1] http://www.scala-lang.org/docu/files/packageobjects/packageobjects.html#
Reply | Threaded
Open this post in threaded view
|

Re: Alternative declaration of a package object: object `package`

Nils Kilden-Pedersen
On Sat, Jan 15, 2011 at 8:46 AM, Arya Irani <[hidden email]> wrote:
Should I use them to replace mypkg.Util ?

Exactly.
Reply | Threaded
Open this post in threaded view
|

Re: Alternative declaration of a package object: object `package`

David Bernard-3


On Sat, Jan 15, 2011 at 16:32, Nils Kilden-Pedersen <[hidden email]> wrote:
On Sat, Jan 15, 2011 at 8:46 AM, Arya Irani <[hidden email]> wrote:
Should I use them to replace mypkg.Util ?

Exactly.

Or not, package object have some limitations (see doc) eg : case object/case class can't be define under package object (IIRC)