Mukhamedali  Zhadigerov
Mukhamedali Zhadigerov

Reputation: 871

Kotlin: javaSetter method is not compiling

I retrieved a property of my class using:

 val prop = businessObject::class.memberProperties.first()

I can do this:

prop.javaGetter

But this method does not compile:

prop.javaSetter

Even though the method exists and is not deprecated

Upvotes: 0

Views: 64

Answers (1)

JB Nizet
JB Nizet

Reputation: 692121

It's not compiling because memberProperties is a Collection<KProperty1>, and KProperty1 doesn't have any javaSetter property. But you can test if the property is in fact a KMutableProperty1, and if it is, after a cast or a smart cast, use its javaSetter property.

As you can see, the documentation helps. Use it.

Upvotes: 4

Related Questions