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


#1

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().  Is this correct? Or is there a way to use the obj.foo syntax for Java objects?

thanks,
Rob


#2

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:

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

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