# How to implement getter

**URL:** <https://discuss.kotlinlang.org/t/how-to-implement-getter/388>\
**Category:** Uncategorized\
**Created:** [December 5, 2014, 7:44am UTC](https://discuss.kotlinlang.org/t/how-to-implement-getter/388 "2014-12-05T07:44:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maxel](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@Maxel](https://discuss.kotlinlang.org/u/Maxel)\
**Post date:** [December 5, 2014, 7:44am UTC](https://discuss.kotlinlang.org/t/how-to-implement-getter/388/1 "2014-12-05T07:44:08Z")

</div>

I have an java interface in a library:

public interface ObjectWithId() {  
&nbsp;&nbsp;Long getId();  
}

How can I implement this interface in Kotlin class?

class TestObject : ObjectWithId {  
&nbsp;&nbsp;public var id : Long? = null  
}

  
causes error: Accidental override

I tried different ways to implement the interface but no success:

class TestObject : ObjectWithId { &nbsp;&nbsp;var id : Long? = null &nbsp;&nbsp;override fun getId() : Long? =id

}

class TestObject : ObjectWithId { &nbsp;&nbsp;var id : Long? = null &nbsp;&nbsp;override get

}

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [December 5, 2014, 9:44am UTC](https://discuss.kotlinlang.org/t/how-to-implement-getter/388/2 "2014-12-05T09:44:29Z")

</div>

Things to take a not of:

- Java getters are not seen as property accessors from Kotlin (this is why simply overriding with a property named "id" does not work). This may be enhanced in the future, though.
- Non-private Kotlin properties produce getters (and setters in case of vars) named "get\<capitalized-property-name\>", i.e. in your case "getId" (this is why you can't define "getId" function alongside with a non-private property "id")

So, one way of achieving what you want is:

```kotlin
class TestObject : ObjectWithId {
    private var id : Long? = null // private

  override fun getId() : Long? =id
}
```

If you really have to have a non-private property, then you need a different name for it (we will support changing platform names for final class members eventually, but curretly it is not possible).
