In Kotlin, do we have a way (or a KEEP) to be able...
# announcements
p
In Kotlin, do we have a way (or a KEEP) to be able to define a Java Method as a getter without the prefix
get
?
y
To change the names of generated accessor methods for properties without explicitly implemented getters and setters, you can use @get:JvmName and @setJvmName
p
The other way around. I have some code in Java (which is not gonna move to Kotlin any time soon) that has getters defined without the prefix and would like to use them as properties in Kotlin (without extfuns)
a
that's not possible right now, you'll need to create a KEEP for that
p
👍
h
Why do we have getters and setters for mutable properties in java anyways?
p
For the same reason that we have them in Kotlin, because of encapsulation. Also, they are read-write, not mutable 😉
I remember a while ago @jw talking about creating a set of annotations for code that is written in Java to be more compatible with Kotlin (Like `Nullable`/`NotNull` but "morer"). Did that get anywhere?
h
Isn't an extension property what you're looking for? https://kotlinlang.org/docs/reference/extensions.html#extension-properties
1
Copy code
val Foo.someProperty: Bar
    get() = somePropertyGetter()
💯 1
p
(without extfuns)
Don't really want to have hundreds of extension properties all over the code
That solution is good for code that you don't have control over, but ideally it would be nice to have an annotation for Java alas:
Copy code
@Property
public String title() { return title }
h
I'm confused – I thought you don't have control over the Java class. If you do: Just rename the getter… ¯\_(ツ)_/¯
p
That's the sort term solution but there is good reasons for keep it without the prefix. - In English it indicates changes on the state of the actor of the sentence - it's noisy "just", that magical word. I thought it would eventually be used 😂