lundi 7 décembre 2020

How to create an object from difinite class using reflection java

I have this code. The object o comes to me from spring's validator. I would like to get rid of the if conditions. How can i implement that.

   if (o instanceof Employee) {
        Employee human = (Employee) o;
    } else  if (o instanceof Postgraduate) {
        Postgraduate human = (Postgraduate) o;
    } else if (o instanceof Student) {
        Student human = (Student) o;
    }




Aucun commentaire:

Enregistrer un commentaire