Posts

Showing posts from July, 2018

Android Kotlin Digest #2

Back again with Kotlin I learnt. Kotlin runs on Java Virtual Machine (JVM). Syntax for declaring variables: Mutable:      var name: Type = value Immutable:  val name: Type = value Type Bit width Double 64 Float 32 Long 64 Int 32 Short 16 Byte 8 Kotlin 1.1 supports underscores ( _ ) in numeric values for readability: val mySalary = 1_000_000 val myCreditCardBill = 20_000 Difference between == and === : val a : Int = 10 val b : Int = 10 (a == b) // gives true  (a === b) // gives true  Note: Here primitive types are compared. When the primitive types are nullable it is turned into references and following is the result: val a : Int? = 10 val b : Int? = 10 (a == b) // gives true  (a === b) // gives false   Note: Here a and b becomes references and hence comparision with === results false. Type converters: 'c'.toInt() 80.toString() A raw string is delimited by a triple quote ( """ ), contains no escaping and can contain n

Android-Kotlin Digest #1

Planning to journal updates on my learning in Android and Kotlin development. This would be mostly from an ​ iOS developer's perspective . I will be writing gist of what I learnt today and anything specific interesting.  To start off below are some things I learnt in Kotlin and differences with Swift.  Some basics of Kotlin:   var  of mutable variables val  of immutable variables / constants Adding variable value in a string "The value of variable is $variable_name" Suffix ?  for variables holding null values  Also has a javascript big arrow =>  function like syntax:   fun sum(a: Int, b: Int) : Int = a + b Conditionals: `if (obj is String) { ... }` and not checks `if (obj !is String) { ... }`  I found switch  statements most unique till now: when (obj) {      1          -> "One" // (case)      "Hello"    -> "Greeting" // (case)      is Long    -> "Long" // (case)      !is String -> "N