algorithm - copy one object's state to another one via java reflection (linear complexity) -


imagine have 2 objects ("from" , "to").
need scan object "from" getters. if object "to" contains correspondent setter, invoke set property value "to" equals property of "from".
type in setter should compatible value returned getter (if not, no invocation performed). compatible means parameter type in setter should same or superclass of return type of getter. i'm sure know approach solve task. need write method "assign", example:

public static void assign(object to, object from) {     class<?> classto = to.getclass();     class<?> classfrom = from.getclass();     method[] methodsto = classto.getmethods();     method[] methodsfrom = classfrom.getmethods();      (method methodfrom : methodsfrom) {         if...     } } 

and each get-method need go through list of set-methods , result of invoking get-method pass parameter correspondent set-method.
in case complexity of algorithm n*m (where n - number of methods in first class, m - in second).
question - how solve task algorithm complexity equals n + m?
there known algorithms or maybe should use implementation of 1 of data structures (hashmap example)?
in advance.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -