简体   繁体   中英

Verifying two references point to the same object in Eclipse

If I'm running the debugger in Eclipse, how do I check to make sure a field in one class is pointing to the same object as the field in another class? I set up breakpoints in both classes, and I'm pretty sure both fields point to the same object, but how would I verify this? (The codebase is much too big to trace the references around.)

I believe Eclipse takes care of this, if I hover over the field in question. (It says, MyClass@79d99e6b. The address refers to the object in RAM, right?)

如果它们具有相同的identityHashCode则它们是相同的

An easy way in eclipse is by looking at the variables tab in debug mode. If the variable has the same id, you can be sure they are the same reference. The id=? is located under the value header on the Variables tab.

The address should point to the RAM address yes. I'm not familiar with eclipse's debugger but if it is giving you an address, and they are the same for both, then yes it should be the same reference.

Also, depending on what language you are using, you could throw in a little variable that is a pointer to the address of the object. (ex, in c++ it's the "&x" syntax if x is the variable. assuming I am remembering that correctly) Then you can check the value of your reference variables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM