Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Understanding of access permissions of packages, classes, objects and members in Scala

Shulou Source: shulou.com Published: 2022-06-03 04:27:50 11月01日 Update

This article briefly analyzes the access permissions of packages, classes and objects through the following program:

Package spark {package navigation {private [spark] class Navigator {protected [navigation] def useStartChar () = println ("navigation") class LegOfJourney {private [Navigator] val distance = 100} private [this] var speed = 200} class Test {new Navigator (). UseStartChar ()} package launch {object Vehicle {private [launch] val guide = new navigation.Navigator}

First of all, analyze the above program. There are two packages navigation and launch under the spark package. The class Navigator is defined in the package navigation, and its access permission is upgraded to all under the spark package, which means that the class can be accessed in the spark package.

The class Navigator,private [launch] val guide = new navigation.Navigator is accessed in the following bread launch.

The method useStartChar () is defined in the class Navigator, and its access permission is set to navigation, which means that the method can only be accessed in the package navigation, such as new Navigator (). UseStartChar () in the Test class.

Private [this] var speed = 200.This can only be accessed in class Navigator, not in other class objects of this class.

Tags: Permissions objects methods programs and will analysis there are two case meaning in bread upgrade member package Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Information Huawei MariaDB Shulou Tech Info