i'm coming from c++ so some things are a little confusing. Apart from the * syntax for pointers not being allowed, is there no such thing as a pointer at all? or rather, are there only pointers in Java? As in, something that stores a memory address to the object we want. Or is it abstracted to a higher level and we don't care about memory addresses at all?
#clarification on references and pointers
1 messages · Page 1 of 1 (latest)
<@&987246683568103514> please have a look, thanks.
everything in java is a std::shared_ptr<Foo> pass-by-value
when java says:
Person first = new Person();
Person second = first;
then this is the same as:
std::shared_ptr<Person> first = std::make_shared<Person>();
std::shared_ptr<Person> second = first;
there is no other memory model in java
(well, u might argue that primitives are internally stored as values directly. but that isnt really observable by u anyways, so lets ignore that for a moment)
so basically what in c are pointers and references are merged into a single concept
(java calls its memory model "references passed by value" but i find that a bit confusing. so maybe ignore that)
its neither pointers nor references
its std::shared_ptr<Foo> passed-by-value
specifically that, and only that
gotcha
its not Person*, its not Person&
its just std::shared_ptr<Person> (and those passed by value)
👌
thanks!
i'll keep the thread open if anyone feels like adding something but my question was answered
(internally the way they are destroyed/garbage collected is ofc different to C++ shared_ptr where its based on ref-counting instead of reachability from roots on the object graph but whatever, details)