Alex Rivera | Logout

What are nested/unnested packages in Scala 2.8?

Asked 2010-05-13T20:55:37.787
23

In Scala 2.7, I could write:

package com.acme.bar

class Bar

.

package com.acme.foo

class Foo {
  new bar.Bar
}

This doesn't compile in Scala 2.8 -- however this does:

package com.acme 
package bar

class Bar

.

package com.acme
package foo

class Foo {
  new bar.Bar
}
  1. What was the motivation for this?
  2. What is the precise meaning, with regards to scope and visibility?
  3. When should I use one form over the other?
Edit
Report

1 Answer

9

Doesn't it give you more control over what is being imported? For example, if there were packages:

package com.acme.foo.client
package com.acme.client

And then from within Foo, wasn't there an annoying ambiguity about which client was being referred to? For example, if you want to do a wildcard import from within Foo:

class Foo {
  import client._ //what is being imported?
}

This might be much more problematic if, instead of client, we had a package com.acme.java:

class Foo {
    val jul = new java.util.LinkedList //compile error; cannot find util
}
answered 2010-05-13T21:24:46.800

Your Answer