well, i used ``` <http://handler.post|hand...
# getting-started
s
well, i used
Copy code
<http://handler.post|handler.post>(object: Runnable{
        ...
        })
and this works. Thanks a lot!
👎 1
👍 1
o
Please don't, it's an ugly workarround. Kotiln offers lambdas to avoid that kind of writing.
s
I wouldn’t be so quick to label anonymous objects as intrinsically “ugly workarounds”. You may be right about there being a better solution here with a Timer, but sometimes you’ll need the object where interface conversions don’t cover every case
I’d agree that @Sergey Shnifer ought to go for a purely lambda-based approach if possible, but there’s nothing wrong about learning how to declare an anonymous class if they’re just going through the book examples for the first time
s
@Olivier but how to use lambdas if i need self-reference and lambdes do not support "this"? (lets assume that i want to use this handler.post API)
r
there's no ugly workaround there, using
object:
is just using less syntactic sugar to write the same code, sometimes it's needed
o
@Shawn My bad, using anonymous objects is not a work arround of Kotlin. It's a work arround in this case when the developer wanted to do a repeated job by calling
handler.postDelayed
instead of creating a repeated job.
@Sergey Shnifer Lambdas are not built for using
this
, lambdas are kind of unamed functions, not objects, there no sense to call
this
. I bet if you have to call
this
inside of lambda there is a conception issue, for this case the conception issue was using Handler to do a loop.