Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report