title: Kotlin - How to pass a Runnable as this in Handler
body: <p>I'm beginner in kotlin. I try to create a task that will repeat every 2 seconds. So I created something like this.</p>
  
  <pre><code>val handler = Handler()
      handler.postDelayed(Runnable {
          // TODO - Here is my logic
  
          // Repeat again after 2 seconds
          handler.postDelayed(this, 2000)
      }, 2000)
  </code></pre>
  
  <p>But in postDelayed(this) it gives error - <code>required Runnable!, found MainActivity</code>. I've tried even <code>this@Runnable</code> but it didn't work.</p>
  
  <p>But when I write the same function like this, it works</p>
  
  <pre><code>val handler = Handler()
      handler.postDelayed(object : Runnable {
          override fun run() {
              // TODO - Here is my logic
  
              // Repeat again after 2 seconds
              handler.postDelayed(this, 2000)
          }
      }, 2000)
  </code></pre>
  
  <p>So why the <code>this</code> keyword doesn't work in first function, but in second function it works good? </p>