Suppose we have the following code snippet:
Cat cat = new Cat(); // The Cat class extends Animal
ArrayList<Animal> animalList = new ArrayList<>();
animalList.add(cat);
cat
is a reference of typeCat
that points to an object of typeCat
animalList.get(0)
is a reference of typeAnimal
that points to the same object as the cat reference.cat == animalList.get(0)
will evaluate totrue
since they are both pointing to the same object.
However, one reference is of type Cat
and the other of type Animal
(position 0 in list), so am I wrong in saying that the references are not entirely equal, even though they point to the same memory location? Am I looking into the terminology too much?