samedi 29 septembre 2018

Get object by String name

Is it possible to get a Object that is instanced from his string name?

I tried this code (and similar) but it does not work:

     boolean test1=false, test2=false, test3=false;
            for(i=1;i<4;i++) {
                try {
                    boolean value_tmp=getApplicationContext().getClass().getField("test"+i);
                } catch (NoSuchFieldException e) {
                    e.printStackTrace();
                }
      }

Thank you in advance.





Aucun commentaire:

Enregistrer un commentaire