“值语义"和“指针语义"是什么意思? [英] What do ‘value semantics’ and ‘pointer semantics’ mean?

查看:124
本文介绍了“值语义"和“指针语义"是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

值语义"和隐式指针语义"是什么意思?

What is meant by ‘value semantics’, and what is meant by ‘implicit pointer semantics’?

推荐答案

Java对对象类型使用隐式指针语义,对基元使用值语义.

Java is using implicit pointer semantics for Object types and value semantics for primitives.

值语义意味着您直接处理值,并传递副本. 这里的重点是,当您拥有一个价值时,您可以相信它不会在您的背后改变.

Value semantics means that you deal directly with values and that you pass copies around. The point here is that when you have a value, you can trust it won't change behind your back.

使用指针语义时,您没有值,而您有一个地址". 别人可能会改变那里的东西,你不知道.

With pointer semantics, you don't have a value, you have an 'address'. Someone else could alter what is there, you can't know.

C ++中的指针语义:

Pointer Semantics in C++ :

void foo(Bar * b) ...
... b->bar() ...

您需要使用*来查询指针的语义,并需要->来调用指针对象上的方法.

You need an * to ask for pointer semantics and -> to call methods on the pointee.

Java中的隐式指针语义:

Implicit Pointer Semantics in Java :

void foo(Bar b) ...
... b.bar() ...

由于您没有使用值语义的选择,因此不需要*,也不需要->和.之间的区别,因此是隐式的.

Since you don't have the choice of using value semantics, the * isn't needed nor the distinction between -> and ., hence the implicit.

这篇关于“值语义"和“指针语义"是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆