I am looking for a Java equivalent of pointer-comparison in C/C++. 

Suppose I am invoking a getSomething() method of an object of a class from a third-party. How do I know if the implementation of the getSomething() is just returning the **same instance** everytime or returning a different instance of the object? 
I am **not** looking to check whether two objects are identical, but need to check if they are the same instance or not. The motivation is, if the 3rd party implementation is creating a new instance everytime, probably I can optimize my code by not invoking the method everytime. Assume getSomething() is invoked by me 1000s of times a second at run-time

From what I read from various articles, I shouldn't rely on hashCode(). In that case what is the way to do this?