java - Get instanced object by String -


is possible object instanced in code string @ runtime?

somthing that:

public string xyz = "aaaa_bbb";  getobject("xyz").some function of string (e.g.: .split("_")) 

thanks

here's example

if it's class field, can name this.

import java.lang.reflect.method;   public class test {       public string stringinstance = "first;second";      public void foo() {           try {             object instance = getclass().getdeclaredfield("stringinstance").get(this);             method m = instance.getclass().getmethod("split", string.class);              object returnvalue = m.invoke(instance, ";");             if(returnvalue instanceof string[])             {                 for(string s : (string[])returnvalue )                 {                     system.out.println(s);                 }             }          } catch (exception e) {             // todo auto-generated catch block             e.printstacktrace();         }     }      public static void main(string a[]){         new test().foo();     }    } 

if it's local method variable trying invoke on, might able @ variable in current method call stack thread.currentthread().getstacktrace() maybe.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -