官术网_书友最值得收藏!

  • 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())
主站蜘蛛池模板: 怀远县| 灵丘县| 晋江市| 阜平县| 祁门县| 平昌县| 克拉玛依市| 锡林浩特市| 双辽市| 黄骅市| 神农架林区| 民县| 舒城县| 北海市| 云安县| 林州市| 虎林市| 裕民县| 临高县| 上蔡县| 太仆寺旗| 白沙| 娱乐| 宣威市| 松滋市| 富川| 新郑市| 永靖县| 开鲁县| 康定县| 清苑县| 太和县| 比如县| 平泉县| 黄梅县| 斗六市| 铜陵市| 皋兰县| 黔东| 体育| 阿巴嘎旗|