- 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())
- JavaScript高效圖形編程
- Mastering Ember.js
- 精通API架構(gòu):設(shè)計、運(yùn)維與演進(jìn)
- 軟件項(xiàng)目管理實(shí)用教程
- Swift語言實(shí)戰(zhàn)精講
- Instant Ext.NET Application Development
- C++寶典
- Extreme C
- Node.js開發(fā)指南
- Unity 2018 Augmented Reality Projects
- R語言數(shù)據(jù)挖掘:實(shí)用項(xiàng)目解析
- Learning Bootstrap 4(Second Edition)
- The Statistics and Calculus with Python Workshop
- jQuery Mobile Web Development Essentials(Second Edition)
- Kohana 3.0 Beginner's Guide