The Busy Java developer's Guide to Scala: Packages and Access Modifiers
Aug 06, 2008, 06:00 (0 Talkback[s])
(Other stories by Ted Neward)
Re-Imagining Linux Platforms to Meet the Needs of Cloud Service Providers
[ Thanks to BlueVoodoo for this link.
"While packaging (and importing) are part of the
encapsulation and packaging story in Scala, a large part of it, as
with Java code, lies in its ability to restrict access to certain
members in a selective way — in other words, in Scala's
ability to mark certain members "public," "private," or somewhere
The Java language has four levels of access: public, private,
protected, and package-level access (frustratingly applied by
leaving out any keyword). Scala:
* Does away with package-level qualification (in a way)
* Uses "public" by default
* Specifies "private" to mean "accessible only to this scope"
"By contrast, "protected" is definitely different from its
counterpart in Java code; where a Java protected member is
accessible to both subclasses and the package in which the member
is defined, Scala chooses to grant access only to subclasses. This
means that Scala's version of protected is more restrictive
(although arguably more intuitively so) than the Java version."