Hi, anyone who would know if it's possible to do ...
# announcements
j
Hi, anyone who would know if it's possible to do following in kt syntax ?
just writing some parametrized test in junit, and I'd like to do the "lambda2" case in array. Can I do that somehow directly or via typealias ?
Copy code
class Object {
    val a: String = "a"
    val b: String = "b"
}

val lambda1 = { v: Object -> v.a }
val lambda2: Object.() -> String = { a }

arrayOf<Any>(
    //lambda1 - works fine
    { v: Object -> v.a },
    //lambda2, how to do this "inlined" - failing, not sure how to tell compiler what type it is
    (Object.() -> String) { a }
)
b
Are you trying to do something like this?
Copy code
{ f: Object.() -> String -> Object().f() }
j
@bsimmons don't think so, I need to pass the Object in it, so not totally sure how to do it with your snippet as you create the instance of Object inside of it
at the end looks like the "nicest" is just property reference like
Copy code
arrayOf<Any>(
   Object::a
)
b
Ok