Primitive vs. Reference Data Types
来源:互联网 发布:淘宝达人如何发帖 编辑:程序博客网 时间:2024/05/21 14:55
转自:http://pages.cs.wisc.edu/~bahls/cs302/PrimitiveVsReference.html
Primitive vs. Reference Data Types
Primitives vs. References
- primitive types are the basic types of data
byte, short, int, long, float, double, boolean, char
- primitive variables store primitive values
- reference types are any instantiable class as well as arrays
String, Scanner, Random, Die, int[], String[]
, etc.- reference variables store addresses
Assignment
- copies the contents of RHS variable into LHS variable
- primitives: the primitive value is copied
- references: the address is copied
- implications: for references the object is not copied, it is shared (reference variables are aliases)
Comparisons (e.g. ==)
- compares the contents of the variables
- primitives: the primitive values are compared
- references: the addresses are compared
- implications: for references the contents of the objects are not compared
Passing Parameters
- terminology:
- formal parameter: the parameter variable that is listed (along with its type) in the method declaration
- actual parameter: the parameter that is given when the method is called
- copies the contents of actual parameter into the formal parameter (i.e., pass-by-value)
- primitives: the primitive value is copied
- references: the address is copied
- implications: for references the object is not copied, it is shared (i.e., actual parameter and formal parameter are aliases)
- primitives: changing the formal parameter's value doesn't affect the actual parameter's value
- references: changing the formal parameter's address doesn't affect the actual parameter's address but changing the formal parameter's object does change the actual parameter's object since they refer to the same object
Returning Values
- returns a result to where the method was called
- primitives: the primitive value is returned
- references: the address is returned
- recall: local variables and parameters are destroyed when the method finishes execution
- implications: a locally created object can survive if it is returned or if it is stored in a data member
原始与参考数据类型
基元与参考
- 原语类型的基本类型的数据
byte, short, int, long, float, double, boolean, char
- 原始变量存储的原始值
- 引用类型的实例化类以及阵列
String, Scanner, Random, Die, int[], String[]
等等。- 引用变量存储地址
分配
- 副本RHS变量的内容到LHS变量
- 原语:原始值被复制
- 引用:地址复制
- 影响 :为参考对象是不可复制的,它是共享的(引用变量是别名 )
比较(如==)
- 比较变量的内容
- 原语:原始值进行比较
- 引用:地址比较
- 影响 :为参考对象的内容不相
传递参数
- 术语 :
- 形式参数:即在方法声明中列出(连同其类型)的参数变量
- 实际参数:即当调用该方法给出的参数
- 副本实际参数的内容到形式参数(例如, 通过按值 )
- 原语:原始值被复制
- 引用:地址复制
- 影响 :为参考对象是不可复制的,它是共享(即实际参数和形式参数是别名)
- 原语 :改变形参的值不会影响实际的参数值
- 引用 :改变形式参数的地址不影响实际参数的地址, 但改变形式参数的对象不改变实际参数的对象,因为它们指的是同一个对象
返回值
- 返回一个结果给其中该方法被称为
- 原语:返回原始值
- 参考文献:地址返回
- 记得:局部变量和参数被破坏时,该方法执行完毕
- 影响 :如果返回它本地创建对象可以存活,或者如果它被存储在一个数据成员
0 0
- Primitive vs. Reference Data Types
- Primitive Types and Reference Types in Javascript
- Working with Primitive Data Types
- Type Fundamentals (.NET: Primitive types, reference types and value types )
- use scalar properties for primitive data types
- use scalar properties for primitive data types
- CSharp - Value types vs reference types
- The Data types reference sheet
- Convert Long to numeric primitive data types example
- C# Concepts: Value vs Reference Types
- C# Concepts: Value vs Reference Types
- [C#] C# Concepts: Value vs Reference Types
- Hibernate Data Types VS JAVA Data Types VS SQL Data Types
- Primitive Types and Objects
- Specializing for primitive types
- 基本类型 primitive types
- 02. Primitive Types
- MATLAB Primitive Types
- 制作PPT“拿来主义” 拿了多少有效资源?
- xml文件的读取
- ssh-keygen的使用方法及配置authorized_keys两台linux机器相互认证
- 在VMware虚拟机中Linux的安装(VMware-11.0.0)
- anaconda install protobuf,pycaffe
- Primitive vs. Reference Data Types
- HttpClient josn网络传输(二进制的byte流)
- Activity与Service通信之自定义接口
- 从服务端架构设计角度,深入理解大型APP架构升级
- IDE eclipse PyDev插件安装
- Linux服务器集群系统(LVS)
- 如何监听Angularjs列表数据是否渲染完毕,配合jQuery操作DOM,指令的规范
- 新建的maven项目不显示src/main/java文件的解决办法
- EXT.NET MVC5 工作随笔06 保存前提示框 及formpanel 的有效性判断