# Convert Java to Kotlin ERROR

**URL:** <https://discuss.kotlinlang.org/t/convert-java-to-kotlin-error/4308>\
**Category:** Support\
**Created:** [August 23, 2017, 3:54am UTC](https://discuss.kotlinlang.org/t/convert-java-to-kotlin-error/4308 "2017-08-23T03:54:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhangmengxiong](https://avatars.discourse-cdn.com/v4/letter/z/9de053/32.png) [@zhangmengxiong](https://discuss.kotlinlang.org/u/zhangmengxiong)\
**Post date:** [August 23, 2017, 3:54am UTC](https://discuss.kotlinlang.org/t/convert-java-to-kotlin-error/4308/1 "2017-08-23T03:54:55Z")

</div>

when i convert my Java code to Kotlin,i got a error,any one can help? thanks~

 ![图片](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/4/4c552cd623eb8a34c5ddfe998db89f048a43fa76.jpg)

---

<div class="post-metadata">

**Author:** ![alanfo](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@alanfo](https://discuss.kotlinlang.org/u/alanfo)\
**Post date:** [August 23, 2017, 10:38am UTC](https://discuss.kotlinlang.org/t/convert-java-to-kotlin-error/4308/2 "2017-08-23T10:38:29Z")

</div>

I’d see if it’s any better if you change the first line to:

```auto
private val playTimeDelayRun: Runnable get() = Runnable {

```

---

<div class="post-metadata">

**Author:** ![zhangmengxiong](https://avatars.discourse-cdn.com/v4/letter/z/9de053/32.png) [@zhangmengxiong](https://discuss.kotlinlang.org/u/zhangmengxiong)\
**Post date:** [August 24, 2017, 1:14am UTC](https://discuss.kotlinlang.org/t/convert-java-to-kotlin-error/4308/3 "2017-08-24T01:14:12Z")

</div>

If i define Runnable like this:

> private val playTimeDelayRun: Runnable get() = Runnable {

Is not every call to get () will re-create a new Runnable return?

---

<div class="post-metadata">

**Author:** ![alanfo](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@alanfo](https://discuss.kotlinlang.org/u/alanfo)\
**Post date:** [August 24, 2017, 10:28am UTC](https://discuss.kotlinlang.org/t/convert-java-to-kotlin-error/4308/4 "2017-08-24T10:28:00Z")

</div>

If it compiles then, yes, a new instance of Runnable will be created on each invocation.

However, if you’re converting from a Java ‘get’ accessor function, then that may be what would have happened anyway.

Also, there’s a danger that if the same instance were used in the recursive call then the code might be circular.

---

<div class="post-metadata">

**Author:** ![zhangmengxiong](https://avatars.discourse-cdn.com/v4/letter/z/9de053/32.png) [@zhangmengxiong](https://discuss.kotlinlang.org/u/zhangmengxiong)\
**Post date:** [August 25, 2017, 1:10am UTC](https://discuss.kotlinlang.org/t/convert-java-to-kotlin-error/4308/5 "2017-08-25T01:10:30Z")

</div>

Maybe I should have this to define:

> private lateinit var playTimeDelayRun: Runnable
> 
> init{  
> playTimeDelayRun = Runnable{…}  
> }

But it’s not simple to write

---

<div class="post-metadata">

**Author:** ![alanfo](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@alanfo](https://discuss.kotlinlang.org/u/alanfo)\
**Post date:** [August 25, 2017, 8:59am UTC](https://discuss.kotlinlang.org/t/convert-java-to-kotlin-error/4308/6 "2017-08-25T08:59:04Z")

</div>

Something like that might work but can you post your original Java code so I can try and work out what the closest Kotlin equivalent would be.
