Scope protection in Scala __scala

Source: Internet
Author: User
Tags modifiers

In Scala, access modifiers can be emphasized by using qualifiers. The format is:

PRIVATE[X] 

Or

PROTECTED[X]

The x here refers to a package, class, or single Instance object to which it belongs. If written as private[x], read "This member in addition to [...] The class in or [...] The classes in the package and their associated pairs are visible, and are private to all other classes.
This technique is useful in large projects that span a number of packages, allowing you to define something that is visible in several child packages of your project but is not always visible to customers outside the project.

Package bobsrocckets{
    Package navigation{
        Private[bobsrockets] class navigator{
         protected[navigation] Def usestarchart () {}
         class legofjourney{
             Private[navigator] val distance = MB
            Private[this] Var Speed = [
            }
        }
        package launch{
        Import navigation._
        object vehicle{
        Private[launch] Val Guide = new Navigator
        }}}

In the above example, the Class navigator is labeled Private[bobsrockets] that means that the class is visible to all classes and objects contained in the Bobsrockets package.
For example, access to navigator from a vehicle object is allowed because the object vehicle is contained in the package launch, and launch is wrapped in bobsrockets, instead, All code outside the package Bobsrockets cannot access the Class navigator.

Original link: http://www.runoob.com/scala/scala-access-modifiers.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.