|
First of all, you should be clear that String in Java is immutable. That is to say, when you assign "aaa" to str in main, and then assign "bbb" to str in changeStr, the virtual machine implicitly creates a String and connects your str reference to the new The String. The original "aaa" has been discarded, and the JVM is responsible for recycling and destroying it.
Then, if you want to compare the addresses of two objects, just use == and that's it. a==b, true if the addresses are equal, it's that simple. As for how to look at the pointer address, I don't know if toString() comes out, but it is completely unnecessary in Java. Abandon the pointer, or you might as well use C++. |
|