# Accessing Java properties - .getFoo() vs .foo?

**URL:** <https://discuss.kotlinlang.org/t/accessing-java-properties-getfoo-vs-foo/520>\
**Category:** Uncategorized\
**Created:** [August 8, 2014, 10:52pm UTC](https://discuss.kotlinlang.org/t/accessing-java-properties-getfoo-vs-foo/520 "2014-08-08T22:52:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RobNik](https://avatars.discourse-cdn.com/v4/letter/r/46a35a/32.png) [@RobNik](https://discuss.kotlinlang.org/u/RobNik)\
**Post date:** [August 8, 2014, 10:52pm UTC](https://discuss.kotlinlang.org/t/accessing-java-properties-getfoo-vs-foo/520/1 "2014-08-08T22:52:31Z")

</div>

It appears that the Kotlin compiler generates methods for var and val properties with the usual Java naming conventions -- getFoo, setFoo, but you can access these as obj.foo in Kotlin. The same does not work for Java -- if a Java class has a property foo, I need to get it with obj.getFoo().&nbsp;&nbsp;Is this correct? Or is there a way to use the obj.foo syntax for Java objects?

thanks,  
Rob

---

<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:** [August 9, 2014, 7:01am UTC](https://discuss.kotlinlang.org/t/accessing-java-properties-getfoo-vs-foo/520/2 "2014-08-09T07:01:56Z")

</div>

Currently there's no property-like syntax for Java getter/setter pairs. We are looking for ways of supporting it.

All you can do for now is define your own extension property for every Java property:

```kotlin
var Foo.bar: Int
  get() = this.getBar()
  set(v) { this.setBar(v) }

// usage:
println(foo.bar)
foo.ba = 1
```
