- 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())
- PHP動(dòng)態(tài)網(wǎng)站程序設(shè)計(jì)
- 深入理解Android(卷I)
- 微信公眾平臺與小程序開發(fā):從零搭建整套系統(tǒng)
- MATLAB圖像處理超級學(xué)習(xí)手冊
- Java深入解析:透析Java本質(zhì)的36個(gè)話題
- Unity Shader入門精要
- 從零開始學(xué)C語言
- 移動(dòng)增值應(yīng)用開發(fā)技術(shù)導(dǎo)論
- C++編程兵書
- 嵌入式Linux C語言程序設(shè)計(jì)基礎(chǔ)教程
- Hack與HHVM權(quán)威指南
- Android高級開發(fā)實(shí)戰(zhàn):UI、NDK與安全
- ASP.NET 4權(quán)威指南
- Java 開發(fā)從入門到精通
- Abaqus GUI程序開發(fā)指南(Python語言)