Using Java classes in Kotlin-style


#1

Is there any simple way to use getters like properties? E.g. use exception.message instead of exception.getMessage() ? Only way I can think of is creating intermediate kotlin class with message property, getter calling getMessage() with custom platformName to avoid name clash. Which is a lot of code to get rid of 5 letters ..


#2

Currently this functionality is not supported. We will probably add it later


#3

Subscribe to this issue to receive notifications: KT-400


#4

With Andrey's reply from the mentioned bug, I has been able to create much shorter workaround: val Throwable.message : String   get() = this.getMessage()!! .. along with some namespaces/imports to be able to use it everywhere

Just to be sure - extension functions does not collide with ‘same JVM signature’ accidental override mentioned in M8?


#5

I actually thought this was a feature. You see, Groovy has this feature, but sometimes it clashes with the fact that in Java some "getters" do not actually represent properties e.g. java.io.File#getCanonicalFile()

I can’t find a reference right now, but I do remember someone raising the issue


#6

No, it will be fine.