Classes in Kotlin can have type parameters, just like in Java:
class Box<T>(t: T) {
var value = t
}
To create an instance of such a class, simply provide the type arguments:
val box: Box<Int> = Box<Int>(1)
But if the parameters can be inferred, for example, from the constructor arguments, you can omit the type arguments:
val box = Box(1) // 1 has type Int, so the compiler figures out that it is Box<Int>
Create the class for all data types.
with class constructor specify<T> and in parameter specify the argument data type T and in method return type also T. so if we pass Int then all the T replace by int. if string then T will be replaced by String.
Ex: val list = listOf<Int>(1,2,3)
vararg is a kind of val and var. just it allows the array or multiple values of any data type.
"*" is also works in a way to do this
Basic example of using Generics with class & method type