The following example t::xreturns a reference to the getter property. How to get the same for the setter?
t::x
class Test(var x: String) {} fun main(args: Array<String>) { val t = Test("A") val getter: () -> String = t::x println(getter()) // prints A val setter: (String) -> Unit = ???? }
Use t::x.setter, it returns MutableProperty0.Setter<T>, which can be used as a function:
t::x.setter
MutableProperty0.Setter<T>
val setter = t::x.setter setter("abc")
The return type t::xis KMutableProperty0<String>one that has a property setter, so you can do this:
KMutableProperty0<String>
setter
val setter: (String) -> Unit = t::x.setter setter("B") println(getter()) // prints B now
Source: https://habr.com/ru/post/1015858/More articles:"from unexpected" when createQuery - javaType 'inout UIButton' does not conform to protocol 'ReactiveCompatible' - iosHow to measure accuracy of predictions using Python / Pandas? - pythonA standalone web application using Hostable Web Core - c #kibana works on docker: how to save the dashboard? - dockerVueJS conditionally adds an attribute for an element - javascriptSpring Boot enabling CORS with application.properties - spring-bootThe production of webpack2 creates a very slow "additional processing of assets", - webpackHow to set a 3-key keyboard shortcut with two key modifiers in Qt? - c ++Display banner message in Ansible - ansibleAll Articles