美文网首页
Remove Assignments to Parameters

Remove Assignments to Parameters

作者: 坚持编程_lyz | 来源:发表于2017-08-10 11:21 被阅读10次
    @Test
        public void DateTest() {
            Date currentdate = new Date();
            System.out.println("before is " + currentdate);
            nextDate(currentdate);
            System.out.println("after is " + currentdate);
        }
    
    
    /**
     * 不要对 方法传递过来的对象进行赋值 , 如果想要修改对象 , 请使用return
     * @param currentdate
     */
    public void nextDate(Date currentdate) {
        Date date = new Date();//取时间
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, -1);//把日期往前减少一天,若想把日期向后推一天则将负数改为正数
        date = calendar.getTime();
        currentdate=date;
        System.out.println(currentdate);
    }
    
    before is Thu Aug 10 11:18:46 CST 2017
    Wed Aug 09 11:18:46 CST 2017
    after is Thu Aug 10 11:18:46 CST 2017
    
    

    相关文章

      网友评论

          本文标题:Remove Assignments to Parameters

          本文链接:https://www.haomeiwen.com/subject/gsfhrxtx.html