java - How to differentiate between a bound callable member reference and a function of the same type in kotlin? -


when comes method signature or definition, there way differentiate

users().indexon(user::id) 

and

users().indexon<user, string> { it.id() } 

? is, specify bound member reference required , not function instance, or vice versa. here signature of above example:

fun <t: sometype, u> indexon(function: (t) -> u): list<u> 

on same note, possible differentiate between constructor reference , function returns type? e.g. query(::somelookup) vs. query { somelookup(args) } (without kotlin.reflect, if possible)

one way distinguish lambda function reference within type system using reflection interface kfunction<t>, example:

fun <t> f(ref: t) t : () -> unit, t : kfunction<unit> { /* ... */ } 

fun g() { println("hello") } f(::g) // ok  f { println("hello") } // error: type parameter bound not satisfied 

though not make work other way around now.

also, found no way distinguish constructor reference type. @ runtime, however, easy through reflection: can check whether javaconstructor of kfunction<*> null.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -