When i try to make a copy of a PVector using get() I get a deprecated warning. whats going on?

edited March 2018 in Questions about Code



  • As for most warnings, simply ignore them! :P

  • edited March 2018

    copy() Get a copy of the vector


  • 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.

  • edited March 2018 Answer ✓


    ... ; it has been superseded by a newer, usually preferable alternative; ...

  • edited March 2018 Answer ✓

    ... when an object, like a PVector, is passed into a function it is passed by reference.

    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

  • edited March 2018 Answer ✓

    replace get() with copy()

    That’s what I meant

  • Yes, if you look at the source code for get() you'll see all it does is call copy() 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.

Sign In or Register to comment.