Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cast Int to Char in Kotlin

Tags:

casting

kotlin

With Java primitives it was easy to cast char code to symbol

int i = 65;
char c = (char) i; // 'A'

How to do the same with Kotlin?

like image 818
Letfar Avatar asked Nov 07 '16 20:11

Letfar


People also ask

How do I cast a datatype in Kotlin?

In Smart Casting, we generally use is or !is an operator to check the type of variable, and the compiler automatically casts the variable to the target type, but in explicit type casting we use as operator. Explicit type casting can be done using : Unsafe cast operator: as.


1 Answers

Use the int.toChar() function to do it.

like image 93
dommer Avatar answered Oct 23 '22 00:10

dommer