Here is an example
If this is a class field, you can get it by name like 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) {
e.printStackTrace();
}
}
public static void main(String a[]){
new Test().Foo();
}
}
If this is a local variable of the method you are trying to connect to, then you may be able to jump to the variable from the current method from the call stack Thread.currentThread().getStackTrace().
source
share