Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

References to generic functions

Is it possible to make reference to generic functions in Kotlin?

For example, let's say I have a function:

fun inline <reified T> appendToString(a: T, b: T) = a.toString() + b.toString

How can you reference this function? This will not compile

var a = ::appendToString<Int>
like image 992
SilverCorvus Avatar asked Nov 19 '16 09:11

SilverCorvus


People also ask

What do you mean by generic function?

Generic functions are functions declared with one or more generic type parameters. They may be methods in a class or struct , or standalone functions. A single generic declaration implicitly declares a family of functions that differ only in the substitution of a different actual type for the generic type parameter.

What is a generic function in R?

Generic functions (objects from or extending class genericFunction ) are extended function objects, containing information used in creating and dispatching methods for this function. They also identify the package associated with the function and its methods.

What is generic function in Swift?

Generic code enables you to write flexible, reusable functions and types that can work with any type, subject to requirements that you define. You can write code that avoids duplication and expresses its intent in a clear, abstracted manner.


1 Answers

Currently it is not supported. But there is a feature request you can support if you would like to see it implemented :) KT-12140

like image 137
daemontus Avatar answered Oct 14 '22 00:10

daemontus