java 内存分析之方法返回值及匿名对象一
package Demo; public class Point { private double x, y, z; public Point(double _x, double _y, double _z) { x = _x; y = _y; z = _z; } public void setX(double _x) { x = _x; } public double getPointDistance(Point p) { return (p.x - x)*(p.x - x) + (p.y - y)*(p.y - y) + (p.z - z)*(p.z - z); } public static void main(String[] args) { Point p = new Point(1.0, 2.0, 3.0); Point p1 = new Point(0.0, 0.0, 0.0); System.out.println(p.getPointDistance(p1)); p.setX(3.0); System.out.println(p.getPointDistance(new Point(1.0,1.0,1.0))); } }
内存分析图: