Generics is a facility for generic programming, allowing classes, interfaces and methods to operate on various types of objects. It basically allows a type to be a parameter to methods, classes and interfaces.

Generics removes the need to typecast by restricting the accepted types and hence guaranteeing run time type safety.

Type Parameters

Type parameters are used to implement generics. The type parameters are placeholders for the actual type to be used with the classes, interfaces or methods.

Example of a Container class which holds a variable of String type:

class StringContainer { var item: String? = null fun set(item…


Comparing references and data in Kotlin

There are three ways to check equality in Kotlin:

1) Structural Equality(‘==’)

‘==’ in Kotlin compares the data contained in the variables. In Java, however, it is used to compare the references of the two variables.

In case of user defined classes, ‘==’ compares the contents if the class is a “data” class. Otherwise, it compares the references.

2) Referential Equality(‘===’)

‘===’ in Kotlin compares the references of the two variables. However, in case of primitives the ‘===’ check is equivalent to the ‘==’ check, i.e, it checks the values.

3) equals method

The ‘equals’ method behaves the same as…


Resolve lambda overhead and overcome type erasure

Inline functions replace the function call with the body of the function itself. Hence the overhead of the function call is saved. The overhead is much more when the function is a higher order function, i.e, contains a lambda as a function parameter. Inline functions come to the rescue and inline the called function as well as lambda body.

Reified Type Parameters along with inline keyword in Kotlin are used in the context of generics. At runtime, any information about the actual type arguments used by the generic class instances are erased, which means we cannot access the generic type…


Speech recognition and voice recognition are technologies that have grown significantly in the course of recent years. Popularity of devices like Alexa, Google Home, Google Voice Assistant and Apple’s Siri speak for it. These advances are changing the manner in which individuals communicate with their gadgets, homes, vehicles, and occupations. Speech recognition allows us to talk to a computer or device that interprets what we are stating so as to react to our inquiry or order. A subset of speech recognition is voice recognition, which identifies a person based on his or her voice. From cell phones to homes and…

Jasmeet Kaur

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store