yonBav
yonBav

Reputation: 1925

How to create a Generic Function in Kotlin

I know it's probably a stupid question, but I can't figure how to create a generic function in Kotlin.

I'm new to Kotlin, but I'm pretty sure it's possible.

I already tried:

fun T GetContent(call: ApplicationCall) : T

and:

fun GetContent<T>(call: ApplicationCall) : T

I Tried searching online and in Stack Overflow questions.

I even looked at the documentation here

I think I'm missing something, because it's supposed to be simple!

Anyway, any help will be highly appreciated!

Upvotes: 1

Views: 66

Answers (1)

Lecagy
Lecagy

Reputation: 489

Directly from the site you quoted:

fun <T> singletonList(item: T): List<T> {
    // ...
}

It's just the wrong syntax ;)

Upvotes: 3

Related Questions