- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
What's the difference between private and private[foo] in package foo?
Thu, 2011-07-28, 10:11
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
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
Fri, 2011-07-29, 10:47
#2
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 SeebergerTwitter: hseeberger
Blog: heikoseeberger.name
Company: Typesafe - Enterprise-Grade Scala from the ExpertsAuthor of Durchstarten mit Scala, a German tutorial-style Scala book
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
Sun, 2011-07-31, 07:37
#3
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 SeebergerTwitter: hseeberger
Blog: heikoseeberger.name
Company: Typesafe - Enterprise-Grade Scala from the ExpertsAuthor of Durchstarten mit Scala, a German tutorial-style Scala book
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
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