How to create a Generic Function in Kotlin

yonBav

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!

Lecagy

Directly from the site you quoted:

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

It's just the wrong syntax ;)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to create a generic function to unmarshal all types?

How to convert multiple functions to create a generic function

How to create generic function in TS and TypeORM?

How to create a generic groupByIndex function?

How to create a generic type for an arrow function in Typescript

How create list with generic argument in Kotlin

How to implement generic function of Interface in Kotlin?

How to create a swift generic variadic function?

Kotlin Generic abstract function

How to create PushRow function with generic parameter type

Kotlin: how to pass collection into generic type of a function

How to create a protocol with a generic function extending type

Kotlin - Generic function references

Kotlin generic function

How to create a callback function in Kotlin?

Create generic higher order function in kotlin

How to create a generic arrow function with react and typescript

How to make a generic function for enumValues<T> in Kotlin?

Kotlin generic function response

How to create a generic array filled with nulls in Kotlin?

How to create generic jquery function for each input

How to create a generic function to load a view controller?

How to check a generic type inside a Kotlin function?

How to create a generic function to replace elements in an array?

How to create a generic array with nullable values in kotlin

How do I make a generic function with generic function as parameter in Kotlin?

How to create a generic function to wrap an async closure?

Generic extension function Kotlin

How to create generic receiver function for slice