Does Java make distinction between value type and reference type

后端 未结 3 1374
灰色年华
灰色年华 2020-12-10 11:04

C# makes distinction of those two. Does java do the same or differently?

相关标签:
3条回答
  • 2020-12-10 11:38

    In Java, the primitives are value types, classes and arrays are reference types.

    0 讨论(0)
  • 2020-12-10 11:39

    Actually, everything in Java is passed by value, references being a special type of value, just like pointers are values in C. More about the semantics here:

    http://javadude.com/articles/passbyvalue.htm

    C# on the other hand, does have real references a la C++, which are unrelated to reference values... Can it get any more confusing than that?

    0 讨论(0)
  • 2020-12-10 11:40

    In Java, all objects and enums are reference types, and all primitives are value types. The distinction between the two is the same as in C# with respect to copy semantics, but you cannot define a new value type in Java.

    0 讨论(0)
提交回复
热议问题