Java Java Data Structures Organizing Data Interfaces

Guillaume Cartier
Guillaume Cartier
2,860 Points

Confused about -- mCreationDate.compareTo(other.mCreationDate) --

I may be forgetting a point previously seen in videos but "other.mCreationDate" confuses me I'd rather write "other.getCreationDate". Is that because it is a private variable in the class ? Anyone can explain that to me please ?

1 Answer

Pedro Cabral
Pedro Cabral
20,135 Points

The field mCreationDate is indeed private. However, other is a Treet and the code that you are writing is in a method called compareTo inside the class that holds that private field, therefore it has access to it. Having access to it, it doesn't need to request the value via getter, it can access the field directly.