I need to get and set a property of another class from a method and therefore need to pass in either the property reference of lambdas for the getter and the setter:
-
Passing in the property reference
otherInstance::property
-
Passing in a lambda for the getter and one for the setter:
{otherInstance.property} // getter
{value -> otherInstance.property = value} // setter
I like the first one, because for me the code is easier to read and shorter, but my alarm bells ring when I read about it on the official documentation, because of the term "reflection". My knowledge from Java is that reflection generally isn't a good thing. Is that also valid with Kotlin? Is it valid with this case? Is one of both ways (property reference or lambdas) more performant or more safe?
Aucun commentaire:
Enregistrer un commentaire