Aaron
Aaron

Reputation: 1332

Is it possible to get access to local variable of method in runtime with Reflection API or with some other things?

Actually here is me code

public class Example {

    public void method () throws InterruptedException {
        int var = 100;        
        Thread.sleep(5000);

        // do some logic
    }    
}

I need to know is the local variable var so incapsulated like wise people say.

Upvotes: 0

Views: 518

Answers (1)

Wyzard
Wyzard

Reputation: 34563

Local variables only exist while the method is running, and there's a separate copy in each activation of the method. Since the reflection API doesn't reflect method activations, you can't get methods' local variables via reflection.

Upvotes: 3

Related Questions