Thanks for the reply, but i should have done a better job of explaining the problem. In D.Shiffman's book "nature of code" he says that when an object, like a PVector, is passed into a function it is passed by reference.
I think he said that to protect the value of the PVector a copy of it should be passed in by using a line of code like:
PVector f = force.get();
When I try this the .get() is underlined in yellow and a warning says "deprecated".
This is what i don't understand.
Answers
As for most warnings, simply ignore them! :P
copy()
Get a copy of the vectorhttps://www.processing.org/reference/PVector.html
Thanks for the reply, but i should have done a better job of explaining the problem. In D.Shiffman's book "nature of code" he says that when an object, like a PVector, is passed into a function it is passed by reference. I think he said that to protect the value of the PVector a copy of it should be passed in by using a line of code like:
PVector f = force.get();
When I try this the .get() is underlined in yellow and a warning says "deprecated". This is what i don't understand.
https://Docs.Oracle.com/javase/9/docs/api/java/lang/Deprecated.html
Actually, all Java objects are already a reference (or pointer or memory address) value. ~O)
All Java arguments passed to functions' parameters are values; either a reference value if it's an Object, or a primitive value otherwise. :-B
replace
get()
withcopy()
That’s what I meant
Yes, if you look at the source code for
get()
you'll see all it does is callcopy()
they're basically identical - https://github.com/processing/processing/blob/master/core/src/processing/core/PVector.java#L378 Sometimes things are deprecated just because the first choice of name wasn't very obvious!@GoToLoop is right - does Shiffman really use the words "passed by reference"?! If so, that's rather a blatant mistake.
Thanks guys for the help. I really appreciate it.