Kotlin


Why with function is not an Extension to Template class?
Why with is not an extension to the Template class? As all the other scope functions are an extension to Template class but not with function. The question is why? How its different from other scope functions? read more
10 May 2021
Kotlin run function
Scope functions are nothing but the functions which define a scope to the calling object. We can apply operations on that object within that scope and return the object itself from that scope function or we can even return the result of that operation or operations from the scope function. read more
09 May 2021
Kotlin with function
Scope functions are nothing but the functions which define a scope to the calling object. We can apply operations on that object within that scope and return the object itself from that scope function or we can even return the result of that operation or operations from the scope function. read more
04 May 2021
Kotlin also function
Scope functions are nothing but the functions which define a scope to the calling object. We can apply operations on that object within that scope and return the object itself from that scope function or we can even return the result of that operation or operations from the scope function. read more
29 Apr 2021
Collections in Kotlin
Collections are a common concept for most programming languages. It is a way of storing similar data types in a single object and iterate over it. Similar to any other language, Kotlin also has Collection defined in kotlin.collections package. read more
22 Apr 2021
any(), none() & all() : Kotlin
Kotlin is a powerful language that reduces a lot of boilerplate code required to perform basic operations in comparison to Java. The classic examples for the same are any, non and all functions which were added to the Iterable interface and Map interface. read more
20 Apr 2021
Kotlin : Single Expression Function
Kotlin is a powerful language that reduced a lot of boilerplate code when compared to Java. The single expression function is the same in terms of reducing the boilerplate code. The single expression function, as his name suggests, is the function that just has a single expression. We can remove the return type of that function, braces as well as return keyword from it. read more
13 Apr 2021
Reified : Kotlin
Generics in any language is the powerful features that allow us to define classes, methods and properties which are accessible using different data types while keeping a check of the compile-time type safety. To get the information about the type of Template class, we will have to use a keyword called reified read more
06 Mar 2021
Kotlin Enum Classes
Enums are special classes which limit the possible values of an object for that class. The possible values defined for that class are final or unchangeable. read more
16 Dec 2020
Android : Share message directly to whatsapp contact
The ideal way any app accepts text or image, video or any other format for sharing is through intent filters defined in the manifest file. Whatsapp also does the same and accepts all possible format (with some size and other limitations) but that will take you to a contact selection screen in Whatsapp. read more
23 Oct 2020
Kotlin Extension Property
Extension functions are really-really helpful while writing code in Kotlin. You don't have to extend the class but you can add the functionality to even a final (non-open) class which will be resolved statically but how about extension properties. Is it even possible? read more
13 Sep 2020
How can I migrate my Android code from Java to Kotlin?
Developers know the benefit of Kotlin over Java for Android app development but they hesitate to try it or even sometimes doesn't know how to start using it in their existing code base. It is very easy to start with at the same time you don't have to migrate the entire codebase in one shot. Instead, you can start writing new features using Klotlin and once you are familiar with Kotlin, you can slowly start the migration of older code. read more
11 Jul 2020
Java or Kotlin, What do you use?
Kotlin is something which was introduced as an official language for Android development in Google I/O 2017. Since then it has grown and evolved a lot. It has multiple benefits and on top of everything, it's really easy to use. Its been three years, still devs or some companies hesitate to use it. read more
06 Jun 2020
Kotlin apply function
Scope functions are nothing but the functions which define a scope to the calling object. We can apply operations on that object within that scope and return the object itself from that scope function or we can even return the result of that operation or operations from the scope function. read more
27 Apr 2020
Difference between Any, Unit and Nothing : Kotlin
We all know about three classes Any, Unit and Nothing in Kotlin which have their own functionality and use cases but we usually confuse between the differences among them and when to use what. read more
03 Mar 2020
Why let function is an Extension to Template class?
Why let is an extension to Template class but not Any class? Not only let, but other helper functions like apply, also, takeIf and takeUnless are also extension functions to the Template class. The question is why? read more
29 Feb 2020
Kotlin let function
Scope functions are nothing but the functions which define a scope to the calling object. We can apply operations on that object within that scope and return the object itself from that scope function or we can even return the result of that operation or operations from the scope function. read more
25 Feb 2020
How extension functions resolved?
how does extension functions are actually resolved? This question is being asked by almost everyone both in and outside the interviews. The shorted or the only answer I get is 'Statically'. What does statically means? read more
15 Dec 2019
Inheritance vs Extension functions
We all know about inheritance which is there in the OOPs concept where one can extend a class and add functionality to it. In the new programming languages, there is something called as extension functions which can add a functionality to an existing class without extending it. read more
02 Dec 2019
partition() : Kotlin
The collection is something which is used by almost everyone. It makes our life easy. List, Set and Map are the best examples of them. Even the programming language in which you are writing code provides you with a few basic operations that can be performed on those collections, But sometimes you need even more operations. read more
23 Oct 2019
‘takeIf’ and ‘takeUnless’ : Kotlin
Ever thought of chaining an if condition? What if we can chain the if condition also and moves or executes the next code in the chain only if the condition is true? Kotlin has something very interesting to achieve the same. read more
10 May 2019
Inline function : Kotlin
Inlining is basically requesting the compiler to copy the (inlined) code at the calling place. When a program is executed and a function is called, CPU stores the memory address of the instruction following the function call, copies the arguments of the function into a stack and finally transfers control to the specified function. read more
05 Apr 2019
Qualified ‘this’ in Kotlin
The only thing we learnt about this pointer in other languages is “this is an implicit pointer which points to the calling object”. As clear from the definition, it points to the object which calls the respective function or property. read more
07 Feb 2019
Type Aliases in Kotlin
Life is painful when you have two or more classes with the same name but different package name and you have to use them both in the same place. Only one import can be added and the other one needs to be referenced by its complete package name dot class name. Every time you use the second class name, you need to use it by the entire package name of that class. read more
23 Dec 2018
Variable number of arguments (vararg) : Kotlin
Sometimes we need a function where we can pass n number of parameters, and the value of n can be decided at runtime. Kotlin provides us to achieve the same by defining a parameter of a function as vararg. We can pass n number of parameters to a vararg variable of the defined datatype or even of a generic type. read more
13 Oct 2018
Infix Notation : Kotlin
Ever imagined calling a public function of a class without dot and parentheses of the parameter in Kotlin. Kotlin provides infix notation with which we can call a function with the class object without using a dot and parentheses across the parameter. Using infix function provides more readability to a function similar to other operators like in, is, as in Kotlin. read more
07 Oct 2018
Object Expression in Kotlin
Sometimes we need to create an object of some class with slight modification, without explicitly declaring a new subclass for it. Java handles this case with anonymous inner classes. Kotlin uses object expression to achieve the same functionality. read more
06 Oct 2018
Equality in Kotlin (‘==’, ‘===’ and ‘equals’)
We often need to compare the data of two variables or objects or the references of two objects in Kotlin. This brings in another question, which equality check should we use in which case. read more
04 Sep 2018
Pair and Triple in Kotlin
It is a very common use case where we want to return two values from a method, can be either of same data type or can be of different data types. What usually we do there is either create some local variables or we create a class with just two variables and return that class object from the method. read more
17 Aug 2018
Extensions as Members : Kotlin
An extension can be defined as members of some other class also. The benefit of defining an extension as a member of the other class is, we can access all the functions and properties of both the classes inside that extension method. read more
27 Jul 2018
Extensions in Kotlin
Kotlin provides the ability to extend a class with new functionality without having to inherit from the class or use any type of design pattern such as Decorator. This is done using a special declaration called extensions. read more
20 Jul 2018
Companion object in Kotlin
Unlike Java or C#, Kotlin doesn’t have static members or member functions. Kotlin recommends to simply use package-level functions instead. If you need to write a function that can be called without having a class instance but needs access to the internals of a class, you can write it as a member of a companion object declaration inside that class. read more
13 Jul 2018
The Nothing Type : Kotlin
What if I say there is a class called Nothing in Koltin. And What does it do? Nothing. This class has no instance and it is used to represent a value which never exists. read more
15 Jun 2018
Label Reference in Kotlin
Any expression in Kotlin may be marked with a label. This can be used to as an identifier. A label can be defined in Kotlin using label name followed by @ sign in front of any expression. read more
08 Jun 2018
Property, Getter and Setter : Kotlin
I started developing Android apps in Java where encapsulation of object-oriented programming was achieved through declaring variables as private fields with their getter and setter as public methods. read more
03 Mar 2018
Kotlin ‘For’ loop
While converting all my java code to kotlin, one of the strange syntax change I observed was the for loop in both the languages. Later I realized in Kotlin, there are few concepts which are completely different from java or any other another language for loops. read more
12 Jan 2018
‘when’ operator in Kotlin
when operator is a replacement of ‘switch’ operator in other languages. ‘when’ operator matches its argument with all the branches until it matches with anyone, else it executes the ‘else’ block. read more
11 Jan 2018
‘in’ operator in Kotlin
‘in’ operator in Koltin is used to check the existence of particular variable or property in a Range or Collection whereas a ‘!in’ operator is just a not of ‘in’ operator and returns true if the condition is false. read more
24 Nov 2017
TypeCheck (‘is’) and Cast (‘as’) in Kotlin
Type check is a way of checking the type(DataType) or Class of a particular instance or variable while runtime to separate the flow for different objects. In few languages, it’s also denoted as Run Time Type Identification (RTTI). read more
23 Nov 2017
Safe calls(?.) vs Null checks(!!) in Kotlin
In Kotlin, the type system distinguishes between references that can hold null (nullable references) and those that can not (non-null references). For example, a normal property can’t hold a null value and will show a compile error. read more
13 Nov 2017
lateinit property in Kotlin
There can be two ways to declare and initialize a var property. The first property type is initialized while declaration itself and doesn’t require a null check (!!) while using it. read more
10 Nov 2017
Higher-order functions in Kotlin
In Kotlin, a function can be passed as a parameter or can be returned from a function, the function which does the same is known as a higher-order function. read more
07 Nov 2017
Backing Field in Kotlin
Backing field is an autogenerated field for any property which can only be used inside the accessors(getter or setter) and will be present only if it uses the default implementation of at least one of the accessors, or if a custom accessor references it through the field identifier. read more
05 Aug 2017