Kotlin, At a Glance (Interview Preparation) : Part-I => Basic types

Swapnil Jadhav
Simple Idea Lab
Published in
1 min readDec 25, 2018

This is useful for people who has basic knowledge of Kotlin but want to revise concepts in a glance. This series will not have any code, but will help you to revise concepts. Hope you will enjoy this journey.

Basic Types

  • Numbers : Double, Float, Long, Int, Short, Byte
  • Literals: Decimals, Hexadecimals, Binary
  • Underscores allowed to make literals more readable
  • Only Explicit conversion are allowed to widen numbers
  • Numbers or booleans are treated as JVM primitive type i.e. it will be boxed only if nullable reference used
  • Internally, arithmetic Operations are performed using Operator overloading
  • Characters: char => cannot be directly replaced by or as numbers
  • Booleans: true/false value
  • Arrays: It is a class which uses [ ] operator overloading to create array. Arrays can have initial value for each element, it can be even null initialised. Kotlin has special primitive type arrays as IntArray, ShortArray etc.
  • Unsigned Integers: types are UByte, UShort, UInt, ULong
  • Unsigned literals: can be written as 1u or 1U
  • Strings: Immutable, Elements are characters to be accessed by index. + is used for concatenation.
  • String literals: Escaped strings and Raw string (“”” Raw “””). Raw string uses trim margin function with default | (pipe) or any other character.
  • String template: It can have simple name as $name or an expression as {$str.length}. It can be used in both escaped and raw strings.

--

--

Swapnil Jadhav
Simple Idea Lab

A forward thinking Android Developer, offering more than 4 years of experience in building, integrating, testing and supporting android application.