This page is no longer maintained — Please continue to the home page at www.scala-lang.org

What's the difference between private and private[foo] in package foo?

3 replies
hseeberger
Joined: 2008-12-27,
User offline. Last seen 1 year 25 weeks ago.
Hi,
package fooclass Bar[A <: Baz]private trait Baz
Error: private trait Baz escapes its defining scope as part of type >: Nothing <: foo.Baz
package fooclass Bar[A <: Baz]private[foo] trait Baz
No error!
Who can tell me what's the difference between private and private[foo] in this case where Baz is a private member of package foo?
Thanks!
Heiko
--

Heiko SeebergerTwitter: hseeberger
Blog: heikoseeberger.name
Company: Typesafe - Enterprise-Grade Scala from the ExpertsAuthor of Durchstarten mit Scala, a German tutorial-style Scala book

Martin Odersky
Joined: 2009-10-07,
User offline. Last seen 42 years 45 weeks ago.
Aw: What's the difference between private and private[foo] in pa
Heiko,

private has a subtly special status in the language specs of both Scala and Java. Check out the discussion of private vs qualified private in the Modifiers section of the SLS. In short, private is the same as Java private, whereas private[foo] is not marked private in the bytecode,
but simply involves a compile-time access check.

Cheers

 -- Martin
hseeberger
Joined: 2008-12-27,
User offline. Last seen 1 year 25 weeks ago.
Re: Aw: What's the difference between private and private[foo]
Thank you!

On 29 July 2011 11:30, martin <odersky [at] gmail [dot] com> wrote:
Heiko,

private has a subtly special status in the language specs of both Scala and Java. Check out the discussion of private vs qualified private in the Modifiers section of the SLS. In short, private is the same as Java private, whereas private[foo] is not marked private in the bytecode,
but simply involves a compile-time access check.

Cheers

 -- Martin



--

Heiko SeebergerTwitter: hseeberger
Blog: heikoseeberger.name
Company: Typesafe - Enterprise-Grade Scala from the ExpertsAuthor of Durchstarten mit Scala, a German tutorial-style Scala book

hseeberger
Joined: 2008-12-27,
User offline. Last seen 1 year 25 weeks ago.
Re: Aw: What's the difference between private and private[foo]
Why doesn't the compile-time check prevent a trait/class defined qualified private (private[foo]) to escape its defining scope? Is this intentional?
Thanks,
Heiko

On 29 July 2011 11:30, martin <odersky [at] gmail [dot] com> wrote:
Heiko,

private has a subtly special status in the language specs of both Scala and Java. Check out the discussion of private vs qualified private in the Modifiers section of the SLS. In short, private is the same as Java private, whereas private[foo] is not marked private in the bytecode,
but simply involves a compile-time access check.

Cheers

 -- Martin



--

Heiko SeebergerTwitter: hseeberger
Blog: heikoseeberger.name
Company: Typesafe - Enterprise-Grade Scala from the ExpertsAuthor of Durchstarten mit Scala, a German tutorial-style Scala book

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland