views:

49

answers:

1

In Java in the equals(Object o) method I can access the private variables of the passed in object without going through its public getters.

public boolean equals(Object o){
    ...
    MyObject other = (MyObject)o;
    return getProp() == other.prop; 
}

How's that?

+3  A: 

Private data is accessible by any instance of that class, even if one instance of class A is accessing the private members of another instance of A. It's important to remember that that access modifiers (private, protected, public) are controlling class access, not instance access.

cletus
Ahhh I see, I'll be sure to look for this in the JLS
non sequitor