# Duplicate method error

**URL:** <https://discuss.kotlinlang.org/t/duplicate-method-error/686>\
**Category:** Uncategorized\
**Created:** [December 8, 2013, 8:25am UTC](https://discuss.kotlinlang.org/t/duplicate-method-error/686 "2013-12-08T08:25:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ziphil](https://avatars.discourse-cdn.com/v4/letter/z/e274bd/32.png) [@Ziphil](https://discuss.kotlinlang.org/u/Ziphil)\
**Post date:** [December 8, 2013, 8:25am UTC](https://discuss.kotlinlang.org/t/duplicate-method-error/686/1 "2013-12-08T08:25:37Z")

</div>

I wrote a simple Kotlin program following:

```kotlin
class Foo() {

  private var foo: Int = 0
  fun getFoo(): Int {
  return foo
  }
}
val f: Foo = Foo()
```

This code was compiled without any error, but I got a runtime error:

```kotlin
Exception in thread "main" java.lang.ClassFormatError: Duplicate method name&signature in class file main/Foo
```

I guess this is because the compiler implicitly creates getFoo() and setFoo(). Is this a bug? Are there any way to avoid this error?

I know accessors declaration is not recommended, but I want to write getters and setters to keep consistency with Java.

---

<div class="post-metadata">

**Author:** ![svtk](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/svtk/32/1499_2.png) [@svtk](https://discuss.kotlinlang.org/u/svtk)\
**Post date:** [December 8, 2013, 9:10am UTC](https://discuss.kotlinlang.org/t/duplicate-method-error/686/2 "2013-12-08T09:10:29Z")

</div>

Hi Ziphil!

The methods “getFoo” and “setFoo” for property are generated exactly for java interop. So you write only

```kotlin
class Foo() {
  var foo: Int = 0
}

```

  
in Kotlin and you use it as

``

```kotlin

```
