- Learn Kotlin Programming(Second Edition)
- Stephen Samuel Stefan Bocutiu
- 205字
- 2021-06-24 14:13:25
Basic types in Kotlin
One of the big changes in Kotlin from Java is that, in Kotlin, everything is an object. If you come from a Java background, then you will already be aware that in Java there are special primitive types that are treated differently from objects. They cannot be used as generic types, do not support method/function calls, and cannot be assigned null. An example is the boolean primitive type.
Java introduced wrapper objects to offer a workaround in which primitive types are wrapped in objects, so that java.lang.Boolean wraps a boolean primitive type in order to smooth over the distinctions. Kotlin removes this necessity entirely from the language by promoting the primitives to full objects.
Whenever possible, the Kotlin compiler will map basic types back to JVM primitives for performance reasons. However, sometimes the values must be boxed, such as when the type is nullable, or when it is used in generics. Boxing is the conversion from a primitive type to a wrapper type, which takes place whenever an object is required but a primitive is presented.
- Python程序設計教程(第2版)
- Spring 5.0 Microservices(Second Edition)
- Flutter開發(fā)實戰(zhàn)詳解
- Apache Spark Graph Processing
- 匯編語言程序設計(第2版)
- Full-Stack React Projects
- Oracle Database 12c Security Cookbook
- 組態(tài)軟件技術與應用
- Python之光:Python編程入門與實戰(zhàn)
- Kubernetes源碼剖析
- Instant Debian:Build a Web Server
- Python Web自動化測試設計與實現(xiàn)
- TypeScript圖形渲染實戰(zhàn):2D架構設計與實現(xiàn)
- Visual Basic程序設計基礎
- 虛擬現(xiàn)實建模與編程(SketchUp+OSG開發(fā)技術)