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

  • 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())
主站蜘蛛池模板: 张家川| 云阳县| 屯留县| 开平市| 望城县| 含山县| 临潭县| 眉山市| 抚宁县| 宜章县| 鸡西市| 许昌县| 武安市| 河池市| 游戏| 宁都县| 屏东县| 安福县| 通江县| 吴堡县| 淳安县| 崇阳县| 永城市| 彭山县| 民勤县| 凌海市| 邳州市| 常山县| 天津市| 巴林左旗| 东阳市| 云龙县| 施秉县| 保康县| 伊川县| 楚雄市| 乐昌市| 京山县| 汤原县| 正定县| 墨竹工卡县|