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

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())
主站蜘蛛池模板: 乌拉特前旗| 遂溪县| 湘西| 巴林左旗| 固阳县| 大埔县| 静安区| 漳平市| 莱芜市| 望城县| 乡城县| 珠海市| 毕节市| 旌德县| 栾城县| 红安县| 偏关县| 垦利县| 洛南县| 濉溪县| 安多县| 孟村| 连江县| 麦盖提县| 邳州市| 嵊泗县| 阳江市| 垦利县| 绥化市| 含山县| 南部县| 汽车| 太康县| 醴陵市| 阳原县| 鹿邑县| 丹阳市| 定陶县| 图们市| 武宁县| 蒙山县|