package author.estone.java; import java.util.Date; public class PassByValue { public static void main(String[] args) { Date d1 = new Date("1 Apr 98"); nextDateUpdate(d1); System.out.println("d1 after nextDay: " + d1);// date的值已被修改 Date d2 = new Date("1 Apr 98"); nextDateReplace(d2); System.out.println("d2 after nextDay: " + d2);// date的值没有被修改 } private static void nextDateUpdate(Date arg) { arg.setDate(arg.getDate() + 1); System.out.println("arg in nextDay: " + arg); } private static void nextDateReplace(Date arg) { arg = new Date(arg.getYear(), arg.getMonth(), arg.getDate() + 1); System.out.println("arg in nextDay: " + arg); } }
Console Output:
arg in nextDay: Thu Apr 02 00:00:00 CST 1998 d1 after nextDay: Thu Apr 02 00:00:00 CST 1998 arg in nextDay: Thu Apr 02 00:00:00 CST 1998 d2 after nextDay: Wed Apr 01 00:00:00 CST 1998
This code is from the book 《Refactoring》.
相关推荐
Note: After installing Sun's JavaMail implementation, you can find many example programs in the demo directory. Installing JavaMail 1.2 To use the JavaMail 1.2 API, download the JavaMail 1.2 ...
After going through this example you will be understand how you can calculate the factorial by using recursion in jsp. To make a program on factorial, firstly it must be clear what is recursion. ...
pass # 对非数字单元格保持原样 # 过滤掉空值 data = [row for row in data if any(row)] ``` 最后,如果要将数据绘制为表格,可以使用matplotlib的pyplot模块: ```python import matplotlib.pyplot as plt ...
A filter configuration object used by a servlet container to pass information to a filter during initialization. flushBuffer() - Method in interface javax.servlet.ServletResponse Forces any content ...
Directory used by the JVM for temporary files (java.io.tmpdir) <br>If you do not pass the "-Dcatalina.base=$CATALINA_BASE" argument to the startup command, $CATALINA_BASE will default to the ...
The goal of this guide is to manage this complexity by describing in detail the dos and don'ts of writing C++ code. These rules exist to keep the code base manageable while still allowing coders to ...
- **The Program Example**: This is a step-by-step breakdown of the code, including comments and explanations for each line. - **#include **: Explanation of how the standard input/output library is ...
Bootstrapping pip By Default Documentation Changes PEP 446: Newly Created File Descriptors Are Non-Inheritable Improvements to Codec Handling PEP 451: A ModuleSpec Type for the Import System ...
目前市场上的应用软件中有超过一半是面向网络的应用,如数据库服务器、游戏、Java Servlets 和 Applets、CGI 脚本等。数据通信不再是两台机器(本地网络或互联网)之间的奇技淫巧,而是日常生活中不可或缺的一部分。...
For example, you can run a system cleanup test that will restart the machine on which an automated test failed. Alternatively, you can create a system test to retrieve information about a machine's ...
### 22、写出发贴数最多的十个人名字的SQL,利用下表:members(id,username,posts,pass,email)(2分) **SQL示例:** ```sql SELECT username FROM members ORDER BY posts DESC LIMIT 10; ``` ### 23.请说明php中...