Is it possible to access a variable which is local to where the method is invoked? Let's say there was a local variable named foo. The method bar that is invoked afterwards needs to access the variable foo without it being passed in as a parameter because I'm going to need to use reflection anyways to get the variable's declared name.
Asked
Active
Viewed 549 times
1
-
Can you post a code example of what you're trying to do? – lucasvw Jul 01 '16 at 18:57
1 Answers
1
Not really, no. The local variable will exist on the stack where reflection can't touch it. It also sounds like you've settled on a bad solution to your actual problem (which you haven't described) and are adamant on using that bad solution, instead of going for better design.

Kayaman
- 72,141
- 5
- 83
- 121
-
I'm making an if-each method, which evaluates an expression (written as a string) for each item in an iterable collection. I have andEach(Iterable iterable, String expression) and orEach(Iterable iterable, String expression). I appreciate your feedback. What do you think I could do differently? – mfgravesjr Jul 01 '16 at 19:14
-
Choose a different programming language probably. That's a rather unsuitable "idea" for a strongly typed language like Java. – Kayaman Jul 01 '16 at 19:18