- Learn Kotlin Programming(Second Edition)
- Stephen Samuel Stefan Bocutiu
- 210字
- 2021-06-24 14:13:32
Access levels
All types and type members have accessibility levels, which constrain where they can be used. As mentioned earlier, not specifying the access level defaults to public. Kotlin comes with three different access levels, which are as follows:
- Internal: This means you can create a new instance of your class from anywhere within your module
- Private: This is more restrictive than the previous one because a class is only visible in the scope of the file defining it
- Protected: You can use this accessibility level only for subclasses; it is not available for the file-level type of declaration
This differs from Java, which does not offer internal, and defaults to package-private.
The internal access level is the equivalent of private for classes when it comes to encapsulation; only this time it is at the module level. A class, interface, and so on can be made visible at the module level if the code isn't accessed from outside the module—for example, if the code is used purely for internal logic. This reduces the API you expose and makes it easier to understand. Furthermore, if a change is required in your module, you can assume that modifying the contract will only break the internal API of the assembly.
- Java逍遙游記
- 國際大學生程序設計競賽中山大學內部選拔真題解(二)
- Learning Network Forensics
- Hands-On Full Stack Development with Go
- RESTful Java Web Services(Second Edition)
- 微課學人工智能Python編程
- Oracle實用教程
- Go語言入門經典
- 官方 Scratch 3.0 編程趣味卡:讓孩子們愛上編程(全彩)
- 大規模語言模型開發基礎與實踐
- AutoCAD基礎教程
- 微信小程序開發邊做邊學(微課視頻版)
- Developing Java Applications with Spring and Spring Boot
- Android應用程序設計
- 精益軟件開發管理之道