Signing a generic function in Kotlin

1

I was seeing the generics part and would like to know why

fun <T> addToList(vararg  arg : T): ArrayList<T> {

and

fun addToList(vararg  arg : T): ArrayList<T> {
    
asked by anonymous 17.12.2018 / 22:19

1 answer

1

The exact reason would have to ask who created this syntax. My "polite kick" is that it would be more complicated to do the parser in another way. He could consider that the T that appears in the argument is even a type called T and not a generic variable of the signature and this would be at least ambiguous. With the initial indication, before any use in the signature, that T is a generic type, its later use makes it clear that it is the generic slot of type and not a concrete type called T .

    
17.12.2018 / 22:29