- Kotlin for Enterprise Applications using Java EE
- Raghavendra Rao K
- 200字
- 2021-06-10 18:49:24
Null safety issue
Accessing a member variable of a null reference will result in a null reference exception. In Java, this is NullPointerException. Java allows us to assign a null value to any variable that we declare, but when we try to use an object reference that has a null value, it throws NullPointerException. This is a common problem to do with programming languages. The language allows us to assign a null reference to a member variable, while also allowing us to access that variable without checking whether it is initialized. It would be preferable if the compiler reports such issues. This is exactly what Kotlin compiler does for us.
In Kotlin, all the types are non-nullable by default. If we try to assign or return a null in the code, it fails to compile. The compiler differentiates between nullable references and non-null references, and the language provides an elegant syntax for null checks. This makes it almost impossible to encounter NPEs in Kotlin. In fact, if we do encounter an NPE, it is likely to be because we explicitly asked Kotlin to throw one, or because the NPE originates from external Java code.
- 新編Visual Basic程序設計上機實驗教程
- 數據科學實戰手冊(R+Python)
- 深度實踐OpenStack:基于Python的OpenStack組件開發
- 一步一步學Spring Boot 2:微服務項目實戰
- Spring 5.0 By Example
- PyTorch自動駕駛視覺感知算法實戰
- Scala Design Patterns
- Mastering Yii
- Hands-On RESTful Web Services with Go
- Getting Started with SQL Server 2012 Cube Development
- 精通網絡視頻核心開發技術
- Python編程與幾何圖形
- EPLAN實戰設計
- Babylon.js Essentials
- GitHub入門與實踐