https://kotlinlang.org logo
Title
r

rook

01/16/2018, 5:41 PM
UserModel.Creator(
_, foo, bar, cat, moo, _ -> User(foo, bar, cat, moo)
)
works fine, but
UserModel.Creator(
_, foo, bar, cat, moo, _ -> {
Log.d("")
User(foo, bar, cat, moo)
}
)
doesn’t work.
m

maplonki

01/16/2018, 5:43 PM
i believe that happens because when you add the closure brackets the compiler detects it as a function returning Unit
r

rook

01/16/2018, 5:43 PM
well, from the error log I posted earlier, it seems to the the result is
((Long, String, String, String, String, String?) -> () -> User)
r

Ruckus

01/16/2018, 5:44 PM
What if you specify
UserModel.Creator<() -> User>(...)
?
r

rook

01/16/2018, 5:45 PM
Unfortunately, that doesn’t work since the expected type from the root factory object is
User
m

mwerschy

01/16/2018, 5:46 PM
Needs to be
UserModel.Creator( {
_, foo, bar, cat, moo, _ ->
Log.d("")
User(foo, bar, cat, moo)
}
)
👍 2
or
UserModel.Creator {
_, foo, bar, cat, moo, _ ->
Log.d("")
User(foo, bar, cat, moo)
}
👍 1
r

rook

01/16/2018, 5:47 PM
thanks, I guess I don’t fully understand the consequences of wrapping code in a closure
r

Ruckus

01/16/2018, 5:47 PM
Ah, I see. In that case do what @mwerschy says. (EDIT: you already did 🙂)