Smart Casting in Kotlin

Smart Casting is a feature of the Kotlin compiler that can rely on the previous conditions and circumstances of a variable to automatically cast that variable to the most appropriate, correct data type for that variable. For example, I have…

The is operator in Kotlin

In Java, we use the instanceOf operator to check if an object is an instance of a certain class or interface? In Kotlin, we will use the is operator! For example, I have an interface with 2 implementations as follows:…

Equality in Kotlin

In Java, when comparing whether 2 objects initialized from a class are equal or not, we need to implement 2 equals() and hashCode() methods for that class and will use the equals() method to compare them. For example, I have…

Variables in Kotlin

In Kotlin, we use two keywords var and val to declare variables. The difference between these two keywords is that var is used to declare mutable variables, and val is used to declare immutable variables. In short, for you to…