Sujit
10/25/2019, 8:00 PMas?
it does not trigger the init {}
method, and I'm losing some info here when doing the casting from Serializable
<http://java.io|java.io>
interface that is setup in init{} block
. So, I'm wondering if there is a way to invoke the init {}
when casting with as?
?Casey Brooks
10/25/2019, 8:05 PMas?
operator doesn’t create any new objects, it just casts it from one type to another, so I wouldn’t expect init { }
to get called from a cast.Sujit
10/25/2019, 8:08 PMinit {}
, and I'm looking to a way to reset those bindings that I do on init to reinitialize in polymorphic situation, where my class has multiple super classes.:
@Serializable
class TestObject: Model(), java.io.Serializable {
init {
super.setSerializer(serializer())
}
}
There the setSerializer
is in Model
class, that I wanna invoke after the casting happens everytime. Does that makes sense?Sujit
10/25/2019, 8:09 PMC++
, I would override a copy constructor for the casting, to do such thing. So, I'm wondering what's kotlin's equivalent? What is guaranteed to be called when as?
is used to cast to the object type?bbaldino
10/25/2019, 8:24 PMas?
does anything like that as it doesn't create an instance, just casts it. if you want to create a new instance you'd have to implement your own clone
method or something, which could work simialr to a c++ copy constructor