我知道比较并compareTo返回一个int值.
例如:
Returns
0 if a equal b
-1 if a < b
+1 if a > b
Run Code Online (Sandbox Code Playgroud)
sort方法调用其中一个compareTo或compare()方法.但是sort方法如何安排list比较或compareTo返回int值.什么是在a compare或compareTo返回int值之后运行的背景场景?如何sort使用返回的int值(-1或0or 1)compare和compareTo
为什么一个包中的子类不能通过超类的引用访问它的超类(在另一个包中)的受保护成员?我正在努力解决这一问题.请帮我
package points;
public class Point {
protected int x, y;
}
package threePoint;
import points.Point;
public class Point3d extends Point {
protected int z;
public void delta(Point p) {
p.x += this.x; // compile-time error: cannot access p.x
p.y += this.y; // compile-time error: cannot access p.y
}
Run Code Online (Sandbox Code Playgroud)