Left Index

Kotlin Type Conversion

In Kotlin Type Conversion is also called Type Casting. Change one data type into another data type is called Type Conversion. For example in java implicit type conversion from small data type(int) to large data type(long) In Kotlin does not support implicit type conversion, you will get an error as shown in below image show error:

In Kotlin helper function used to explicit type conversion. For example:

var emp = 100;
var demo: Long = emp.toLong()

Below are the list of helper function, that can use for explicit type conversion:

  • toByte()
  • toShort()
  • toInt()
  • toLong()
  • toFLoat()
  • toDouble()
  • toChar()
  • toString()
  • toBigDecimal()
  • toFloat()
  • toDouble()

There are many explicit type conversion methods in Kotlin. Note: There is No helper function available to convert into boolean type.