package cn;
import java.util.Date;
/**
* @ClassName User
* @Description TODO(这里用一句话描述这个类的作用)
* @author feizhou
* @Date 2017年9月17日 下午3:14:53
* @version 1.0.0
*/
public class User {
private String id;
private Date date;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public User(String id, Date date) {
super();
this.id = id;
this.date = date;
}
public static void main(String[] args) {
User user=new User("1",new Date());
System.out.println(user.getDate());
Date d=user.getDate();
double oneDay=24*60*60*1000;
try {
Thread.sleep(5000);//休息5秒
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
d.setTime(d.getTime()-(long)oneDay);
System.out.println(user.getDate());
// 输出:
// Sun Sep 17 15:31:00 CST 2017
// Sat Sep 16 15:31:00 CST 2017
}
}
前几天有个同事问我,为什么输出内容不一样,我现在把内存图画出来,说明一下
Date d=user.getDate();的内存地址是user对象date属性值的地址