请输入您要查询的百科知识:

 

词条 Value type and reference type
释义

  1. Classification per language

  2. Boxing and unboxing

  3. See also

  4. References

In computer programming, data types can be divided into two categories: value types and reference types. A value of value type is the actual value. A value of reference type is a reference to another value.[1][2]

Classification per language

Language Value type Reference type
C++[3] booleans, characters, integer numbers, floating-point numbers, classes (including strings, lists, maps, sets, stacks, queues), enumerations references, pointers
Java[4] booleans, characters, integer numbers, floating-point numbers arrays, classes (including immutable strings, lists, dictionaries, sets, stacks, queues, enumerations), interfaces, null pointer
C#[5] structures (including booleans, characters, integer numbers, floating-point numbers, fixed-point numbers, lists, dictionaries, sets, stacks, queues, optionals), enumerations classes (including immutable strings, arrays, tuples, lists, dictionaries, sets, stacks, queues), interfaces, pointers
Swift[6][7] structures (including booleans, characters, integer numbers, floating-point numbers, fixed-point numbers, immutable strings, tuples, lists, dictionaries, sets, stacks, queues), enumerations (including optionals) functions, classes, interfaces
Python[8] classes (including immutable booleans, immutable integer numbers, immutable floating-point numbers, immutable complex numbers, immutable strings, byte strings, immutable byte strings, immutable tuples, immutable ranges, immutable memory views, lists, dictionaries, sets, immutable sets, null pointer)
JavaScript[9] immutable booleans, immutable floating-point numbers, immutable symbols, immutable strings, undefined, prototypes (including lists, null pointer)
OCaml[10][11] immutable characters, immutable integer numbers, immutable floating-point numbers, immutable tuples, immutable enumerations (including immutable units, immutable booleans, immutable lists, immutable optionals), immutable exceptions, immutable formatting strings arrays, immutable strings, byte strings, dictionaries (including pointers)

Boxing and unboxing

{{main|Object type (object-oriented programming)#Boxing}}

Programming languages that distinguish between value types and reference types typically offer a mechanism, called boxing, to wrap some or all of their value types in reference types. This permits the use of value types in contexts expecting reference types. The converse process (to unwrap the value type) is known as unboxing.

See also

  • Primitive data type
  • Composite data type

References

1. ^{{cite book |last=Brown |first=Erik E. |date=2006 |title=Windows Forms in Action |url=https://books.google.fr/books?id=PrZQAAAAMAAJ&q=%22value+type%22+%22reference+type%22&dq=%22value+type%22+%22reference+type%22&hl=fr&sa=X&ved=0ahUKEwiamJGq0bncAhVPExoKHR21DQA4HhDoAQhZMAY |location=Shelter Island, New York |publisher=Manning |page=703 |isbn= 978-1-932-39465-8 |author-link= }}
2. ^{{cite book |last=Stephens |first=Rod |date=2014 |title=C# 5.0 Programmer's Reference |url=https://books.google.fr/books?id=DEM_AwAAQBAJ&pg=PA57&dq=%22value+type%22+%22reference+type%22&hl=fr&sa=X&ved=0ahUKEwiJyMCA1LncAhVhxYUKHQZECVI4ZBDoAQhCMAQ#v=onepage&q=%22value%20type%22%20%22reference%20type%22&f=false |location=Indianapolis, Indiana |publisher=John Wiley & Sons |page=57 |isbn=978-1-118-84728-2 |author-link= }}
3. ^http://en.cppreference.com/w/cpp/language/type
4. ^https://docs.oracle.com/javase/specs/jls/se10/html/jls-4.html#jls-4.3
5. ^https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/types
6. ^https://docs.swift.org/swift-book/LanguageGuide/ClassesAndStructures.html
7. ^https://docs.swift.org/swift-book/LanguageGuide/Closures.html
8. ^https://docs.python.org/3/library/stdtypes.html
9. ^https://www.ecma-international.org/ecma-262/#sec-ecmascript-language-types
10. ^https://caml.inria.fr/pub/docs/manual-ocaml/core.html
11. ^https://caml.inria.fr/pub/docs/oreilly-book/html/book-ora026.html
{{DEFAULTSORT:Value Type}}

1 : Data types

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/11 12:02:24