- 浏览: 73408 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
george.gu:
lqjacklee 写道怎么解决。。 First: Conf ...
Bad version number in .class file -
lqjacklee:
怎么解决。。
Bad version number in .class file -
flyqantas:
would you pleade left more mate ...
UML Extension
What's saved in Object Reference?
We can treat the Java Object will be managed in two parts:
- Obejct definition and its reference to Memory Heap which contains object's attribute and data contents.
- Data contents in memory heap which is known by Object by reference.
The following Junit test code prove this understanding.
class TempString { private String temp; public TempString(String str) { this.temp = str; } public String getTemp() { return temp; } public void setTemp(String temp) { this.temp = temp; } } @Test public void testObjectReference() { TempString obj = new TempString("test"); TempString objb = obj; obj = null; TempString objc = obj; assertNull(obj); assertNull(objc); assertNotNull(objb); assertEquals("test", objb.getTemp()); }
Set Object to be NULL: Object=null
We can use the "Object=null" to release memory. But keep in mind, it is not "=null" operation itself make memory released. Garbage Collector will clean and release memory heap later if it found there is no any reference to the data (in memory heap).
List keep the Object reference but not object itself
From below test, we can know that: Collect keep the object reference to its memory heap.
@Test public void testListKeepOriginalAfterSetObjectTobeNull() { TempString obj = new TempString("test"); List<TempString> list = new ArrayList<TempString>(); list.add(obj); obj = null; assertNull(obj); assertEquals("test", list.get(0).getTemp()); List<String> list2 = new ArrayList<String>(); String a = new String("StringObject"); String b = "testPrimitive"; list2.add(a); list2.add(b); a = null; b = null; assertEquals("StringObject", list2.get(0)); assertEquals("testPrimitive", list2.get(1)); List<Integer> list3 = new ArrayList<Integer>(); Integer intA = new Integer(1); Integer intB = 5; list3.add(intA); list3.add(intB); intA = null; intB = null; assertNotNull(list3.get(0)); assertEquals(1, list3.get(0).intValue()); }
Java is Pass-by-Value or Pass-by-Reference?
To be Updated. Here I list the doc I found from Internet:
- Please refer to: http://javadude.com/articles/passbyvalue.htm.
Clone your Java Object
To be Updated. Here I list the doc I found from Internet:
发表评论
-
javax.naming.CommunicationException: remote side declared peer gone on this JVM.
2012-07-11 09:44 2376javax.naming.ServiceUnavailable ... -
Generate special format numbers
2012-04-27 00:06 934DecimalFormat df = new DecimalF ... -
Singleton Service in Weblogic Cluster
2012-03-21 00:12 709http://blog.csdn.net/mobicents/ ... -
Scheduled ThreadPool Executor suppressed or stopped after error happen
2012-03-20 16:54 1042ScheduledThreadPoolExecutor ... -
Bad version number in .class file
2012-01-27 00:35 892Bad version number in .class fi ... -
User Data Header in SMPP SUBMIT_SM
2012-01-25 22:30 2331SMPP optional Parameters for ... -
jQuery study
2011-12-28 00:44 0to be study -
java.util.Properties: a subclass of java.util.Hashtable
2011-12-13 06:57 774I met a problem this afternoon ... -
Jmock usage
2011-12-02 05:37 0Discuss how Jmock working. -
Oracle Index Usage
2011-12-15 05:26 623Like a hash mapping for record' ... -
AOP(2):AOP与动态代理JDK Proxy and Cglib Proxy
2011-05-12 16:20 1022使用动态代理(JDK Proxy 或者Cglib Proxy) ... -
AOP(1):应用中的几个小故事
2011-05-09 21:49 973I had heared about AOP almost 7 ... -
异步系统设计:push vs pull
2011-05-02 23:59 1138今天讨论问题时,有个同事说系统A是主动去系统B里“拿”消息,我 ... -
Velocity Usage
2011-04-28 22:52 1002You can find velocity mannua ... -
Java Regular Expression (Java正则表达式)
2011-04-23 06:58 931In current Project, we need to ... -
XML Parser:DOM + XPath
2011-04-23 06:30 1199There are many kinds of XML Par ... -
File upload and download in Java Web Application.
2011-04-21 21:08 1714最近在项目中遇到一个下载文件的老问题。之所以说是老问题,因为在 ... -
Manage zip content using Java APIs
2011-04-21 18:14 1038JDK provide a set of utils to c ... -
Beanshell: how and where to use beanshell
2011-04-21 00:33 2094How to use beanshell beansh ... -
OXM: JAXB2.0 in JDK1.6
2011-04-20 22:53 12371.1.1 JAXB 2.0: ObjectàXML ...
相关推荐
1、为什么要宁以pass-by-reference-to-const 替换 pass-by-value 效率方面 缺省情况下,C++以by value 方式传递对象至(或来自)函数。 除非你另外指定,否则函数参数都是以实际实参的副本为初值,而调用段所获得的...
Between pass-by-value and pass-by-reference? It is important to get these decisions right at the outset, because an incorrect choice may not become apparent until much later in the development ...
在Javascript中测试数组的按值传递与按引用传递。 解释 我最初查看Javascript是按值传递还是引用传递,发现除对象之外,它按值传递。 我创建了一个测试环境,该环境将创建一个大的整数数组并将该数组多次传递给函数...
在Java编程中,"passing with default" 或 "pass by reference vs pass by value" 是一个常见的讨论话题。Java中所有的参数传递都是按值传递,这意味着当你将一个变量传递给方法时,方法接收的是该变量当前值的一个...
You have permission to print out the Reference Manual (or other related documentation) in whole or in part in support of the use of this software. ------ Support for Microsoft through Visual ...
在Delphi编程语言中,函数调用时参数的传递方式主要分为两种:传值(Pass-by-value)和传址(Pass-by-reference)。这两种传递方式在实际编程中有着本质的区别,理解它们之间的差异对于编写高效、安全的代码至关重要...
- Stack Overflow上的相关讨论:https://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value 通过以上分析和扩展阅读,希望能帮助大家更好地理解和掌握Java中对象传递的关键概念。
Java中的参数传递有两种主要的方式:值传递(Pass-by-value)和引用传递(Pass-by-reference)。虽然Java主要是基于值传递的,但在处理对象时,实际上传递的是指向对象的引用,因此在某些情况下也会被称为引用传递。...
Returns the servlet container attribute with the given name, or null if there is no attribute by that name. getAttribute(String) - Method in class javax.servlet.ServletRequestWrapper The default ...
条款20:宁以pass-by-reference-to-const替换pass-by-value prefer pass-by-reference-to-const to pass-by-value. 条款21:必须返回对象时,别妄想返回其reference don't try to return a reference when you must ...
参数的传递方式主要有两种:值传递(Pass-by-value)和引用传递(Pass-by-reference)。Java主要采用值传递的方式。 ##### 1. 值传递 当我们将基本数据类型作为参数传递给方法时,实际上是传递了该数据的值的一个...
The default stepping value is 3. - Added ability to disable MONITOR/MWAIT support through .bochsrc CPUID option. The option is available only if compiled with --enable-monitor-mwait configure ...
The Simple Mail Transfer Protocol (SMTP) is defined by RFC 821 . It defines the mechanism for delivery of e-mail. In the context of the JavaMail API, your JavaMail-based program will communicate ...
- **传引用与传值的区别**:Java不支持传引用(`pass-by-reference`),这与C++等语言有所不同。传引用是指传递变量的地址,而不是其值。 #### 四、方法重载与构造方法重载 - **方法重载概述**:方法重载(Overloading...
This will error faulty NICs that are not detected by the BurnInTest auto NIC detection mechanism. - Minor change to the 2D memory test when run with the 3D test (multiple large windows) and the ...
- Java使用传值调用(pass-by-value),即传递给方法的是实参的一个副本。如果是引用类型的参数,则传递的是引用的副本。 - **封装(encapsulation)**: - 使用setter和getter方法可以增强对象的安全性。通过将实例...
因此当这四个子语言相互切换的时候,可以更多地考虑高效编程,例如pass-by-value和pass-by-reference在不同语言中效率不同 总结: C++高效编程守则视状况而变化,取决于使用哪个子语言 2. 尽量以const, enum, inline...
directive because it is not set or is mistyped, a default value will be used. ; The value can be a string, a number, a PHP constant (e.g. E_ALL or M_PI), one ; of the INI constants (On, Off, True, ...