WEB Button DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Kotlin - Generics

In this chapter we discuss Data classes of Kotlin programming language.

Kotlin developer has introduced two new keywords “out” and “in” to make Kotlin codes more readable and easy for the developer.

List is a class in Kotlin, List<String> is a type in Kotlin

Let's see example generics is implemented in Kotlin.

fun main(args: Array<String>) {

   val integer: Int = 1
   val number: Number = integer
   print(number)
}

“Int” is a subclass of Number class, hence the type conversion happens automatically at runtime and produces the output as “1”.

Kotlin generics is defined by <T> where “T” stands for template, which can be determined dynamically by Kotlin complier.