posted 13 years ago
It isn't difficult for the programmer looking at the code: if it's a local variable then it's in the stack. If it's a class-level variable then it's part of an object which is in the heap. And this never changes.
There aren't any features in the API which give you any information about variables. There are plenty which give you information about the objects they refer to (and which are always in the heap, for what it's worth). Like the designers of the API, I can't envision any use cases for finding out where a variable is allocated. Do you have one? I too would be interested to know what it is.