- 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.
- Vue.js 3.x快速入門
- 深入實踐Spring Boot
- 我的第一本算法書
- Mastering PHP Design Patterns
- Mastering Ubuntu Server
- Julia Cookbook
- 數據結構(C語言)
- 人人都懂設計模式:從生活中領悟設計模式(Python實現)
- Mastering Linux Network Administration
- HTML5從入門到精通 (第2版)
- 用案例學Java Web整合開發
- Python機器學習之金融風險管理
- Clojure for Machine Learning
- Hands-On Kubernetes on Windows
- Moodle 3 Administration(Third Edition)