how can compiler know y!=this?
the statment "a and b are the same object" is determined at runtime.
so, it is not feasible to say "method can only access private members of the object itself".
in other words, access protection is at class-level. not object level.
class You{
private int i;
You(int i){
this.i = i;
}
boolean compareTo(You y){
return this.i > y.i;
}
}
public class Ptest{
public static void main(String[] args){
You y1 = new You(4);
You y2 = new You(3);
System.out.println(y1.compareTo(y2));
}
}