Guys, is there a way to automatically make availab...
# announcements
g
Guys, is there a way to automatically make available the getters and setters of a property? For example
Copy code
class MyIn {
	fun myFunction() {
		println("myFunction")
	}
}

class MyOut {
	val myIn: MyIn = MyIn()
}

class Test {
	fun main() {
		val myOut = MyOut()

		// Calling myFunction from the myIn object this way. Maybe something with delegate?
		myOut.myFunction()
	}
}
t
You can refactor it to class MyOut(val myIn: MyIn = MyIn()) which will give you access via MyOut.myIn.myFunction()
or you can just pass a lamba to it class MyOut(val myFunction: () -> Unit = { MyIn().myFunction() } )
g
@Tsvetozar Bonev, interesting. About the second solution. Do we have a way to automatically create this for a dynamic number of functions? For example, MyIn having 10 or more functions. And on some other part of the code a class MyIn2 having 15, other MyIn3 having 20, etc. What I mean is automatically mapping all functions of the inside object to have an external getter?
s
Yeah what pavlo posted.. Seems like a good use of delegation
t
@Danilo I don't think there is a way to automatically do that, maybe some reflection magic imo the delegation would work better for this case