Type system

In Kotlin, everything is an object. There are no primitive variables.

The following are the important numeric types:

  • Double--64 bit
  • Float--32 bit
  • Long--64 bit
  • Int--32 bit
  • Short--16 bit
  • Byte--8 bit

Unlike Java, Kotlin does not treat characters as a numeric type. Any numeric operation on a character will result in a compilation error. Consider the following code:

    var char = 'c'    //Operator '==' cannot be applied to 'Char' and 'Int'    //if(char==1) print (char);    Null safety

Java programmers are very familiar with java.lang.NullPointerException. Any operations performed on object variable referencing null will throw NullPointerException.

Kotlin's type system aims to eliminate NullPointerException. Normal variables cannot hold null. ...

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.