Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
207 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...