Go through a data structure looking for them to be the same (reference to memory)?

0

I have a class that is Place that has a series of data, these I store in an array given that at the time of constructing the objects there can be several with it, so the idea is to go through the array but comparing at the level of reference.

How good is this practice in java? In the university we do use it but I've seen negative comments out there.

    
asked by eslop 02.12.2016 в 11:07
source

1 answer

2

If what you need is to know if two different variables point to the same object, it is good practice and is correct. If what you want to know is if two different variables point to objects that contain the same data but are not the same (clones) then you do not have that if you do not implement the equals method.

    
answered by 02.12.2016 / 11:15
source