我有一个名为Point
如下的类:
public class Point {
public int x;
public int y;
public Point(int X, int Y){
x = X;
y = Y;
}
public double Distance(Point p){
return sqrt(((this.x - p.x) * (this.x - p.x)) + ((this.y - p.y) * (this.y - p.y)));
}
protected void finalize()
{
System.out.println( "One point has been destroyed.");
}
}
我有一个来自此类的对象,命名p
如下:
Point p = new Point(50,50);
我想删除这个对象,我搜索了怎么做,我找到的唯一解决方案是:
p = null;
但是Point的finalize方法在我做完之后就不起作用了。我能做些什么?