- Kotlin Blueprints
- Ashish Belagali Hardik Trivedi Akshay Chordiya
- 160字
- 2021-07-02 21:50:22
Using datatypes and conversion
In Kotlin, everything is an object. Kotlin has pretty much the same number of related data types compared to Java. But they are not exactly the same.
In Java, the following is true:
int num=10;
double bigNum=num;
But in Kotlin if you try to do such a thing it will give a compile-time error. This means implicit widening is not allowed in Kotlin. However, the main thing we want to discuss in this section is, with every number type Kotlin supports some explicit conversion and that can fill the gap of not having an implicit widening feature. Also, we often use utility methods from Java wrapper classes such as Integer.parseInt(), Float.valueOf(), and so on.
Every number type supports the following conversions:

Let's say a class is expecting the int value and you have the float value as a parameter, you can use toInt() and get the job done. No casting is required:
RoundedBitmapDisplayer(someFloatValue.toInt())
- Unity 2020 Mobile Game Development
- Learn Scala Programming
- C語言程序設計學習指導與習題解答
- ANSYS Fluent 二次開發指南
- C語言程序設計
- C陷阱與缺陷
- Python數據科學實踐指南
- Node.js實戰:分布式系統中的后端服務開發
- Learning Shiny
- Java編程指南:語法基礎、面向對象、函數式編程與項目實戰
- Practical Responsive Typography
- Python程序設計現代方法
- 軟件測試項目實戰之功能測試篇
- Learning Rust
- Learning C# by Developing Games with Unity 3D Beginner's Guide