Posts

Nullability in Kotlin

Image
Null Safety or Nullability  We have discussed the basic introduction of Kotlin, if you wish to have a look Here you go !! Kotlin includes nullable types, which can represent the absence of value.   Basically, we can use it to represent the value and absence of that value as well. You might have heard of options in swift. It's the same way.   var error: Int? Marking with? This means either it will have the Int or no value.   error = 100 error = nullvar error: Int? As you know in swift optional value being wrapped in the optional type so when you try to print the value it will not be like a primitive Int value.   You need to unwrap it the same way we are also going the do the same.   Not-null assertion operator   (!!)  which is used to unwrap the value from it. error !! + 1 Seems it like as in iOS, force unwrapped an optional value with null as the value will make the app crash same way here as well you will get the null-pointer excepti...

Introduction to Kotlin

Image
  Kotlin: Introduction:  It's created by Jetbrains. Kotlin can be used for JVM and Android. It is a statically type-safe language.   As we all know that Java complied code called bytecode. Which runs on Java Virtual Machine. So we can convert Kotlin code to java. Java is platform-independent which we will be able to run Kotlin as well.   Which is great !!!   Now Google has announced Kotlin is the official language for Android.  Kotlin's main feature is interoperability with Java.  Why Kotlin over Java? Interoperable with Java Easier to code Increase productivity   Nullability issue:  Cons of Java in which it is called a Null Pointer Exception. Kotlin’s type system is built to eliminate Null Pointer Exception. Reference: https://kotlinlang.org/docs/reference/ Happy Coding 😊