```fun interface MCall2{ fun updateMyText(text...
# announcements
a
Copy code
fun interface MCall2{
    fun updateMyText(text: String)
}
class Testing : MCall2 {
    var st: String? = null
    override fun updateMyText(text: String){
        st = text
    }
    init {
        print(st)
    }

}
@Test
    fun check_the_call_back(){

        Testing().updateMyText("trying to re assign")


    }
I was trying to reassign
st
value with in SAM is it possible tho , this returns null btw
y
Well basically from what I can understand you want to change that text then print it out right? Well in that case then you actually need to have that print statement inside of
updateMyText
instead of it being in the
init
block
a
Well the goal is
updateMyText()
to re assign the just value and on the
init{}
actually I wasn't using it, instead I used function to print out the value just for simplicity reading used
init
since there's not that much difference
y
well it does depend on how your actual code is structured.
init
only gets run once right when the object is created. If possible, could you provide an example of what your actual code was?
a
Ok well
Copy code
fun interface MCall2{
    fun updateMyText(text: String)
}
class Testing : MCall2 {
    var st: String? = null
    override fun updateMyText(text: String){
        st = text
    }
    fun reveal() {
        print(st)
    }
    fun `return`():String? = st

}
@Test
    fun check_the_call_back(){

        Testing().updateMyText("trying to re assign")
        Testing().reveal()
        print(Testing().`return`())


    }
y
There we go. Well basically what you're doing right now is that you're creating a new instance of the Testing class every time that you're calling a method on it, and so in reality when you call
reveal
you're calling it on a brand new instance. The solution here is simple, in your test method, you need to store a Testing object and then call methods on it. Here's basically how it needs to be:
Copy code
@Test
    fun check_the_call_back(){
        val myTestingObject = Testing()
        myTestingObject.updateMyText("trying to re assign")
        myTestingObject.reveal()
        print(myTestingObject.`return`())
    }
a
Oof I never realised that ,thank you