Q:

Method not changing variables

I have a bit of a problem here and really, I don't get why. I have written plenty of code that takes field variable in the parameters and then changes them. Here is the method:
public void hit(Array<Card> cards, int score, float spacing) {
    // Take the last card from the deck and store it in a temp card variable
    nextCard = deck.pop();
    // If the card value is equal to 11, it must be an ace, if it puts the
    // player over 21 it makes the ace have a value of 1
    if ((nextCard.getCardRealValue() == 11)
            && nextCard.getCardRealValue() + score > 21) {
        nextCard.setCardRealValue(1);
    }
    // Add the card to the array passed in the parameter
    cards.add(nextCard);
    // Check the last card in the array (the one just added) grab it's value, add it to total
    score += cards.peek().getCardRealValue();
    // Shrink the main deck, not sure if neccessary but not point in leaving empty memory
    deck.shrink();
    // Move the sprites 20 pixels
    spacing -= 20;
    // tbh this bit never gets called, stupid useless code lol
    if (score > 21) {
        if (cards.peek().getCardRealValue() == 11) {
            cards.peek().setCardRealValue(1);
            score -= 10;
        }
    }
    // if the first card has not been checked and score is over 21, if it is an ace change it to a value of 1
    if (!aceOne && score > 21 && cards.get(0).getCardRealValue() == 11) {
        cards.get(0).setCardRealValue(1);
        score -= 10;
        aceOne = true;
        // Same as above, just if second card is ace
    } else if (!aceTwo && score > 21
            && cards.get(1).getCardRealValue() == 11) {
        cards.get(1).setCardRealValue(1);
        score -= 10;
        aceTwo = true;

    }
}

This is basically the method that gets called when the player decides to "hit", it takes the array that holds the cards of the player, the players score and then this thing which I have called spacing, this basically shifts the card sprites -20 to the left to stop then trailing to the right of the screen and looking fugly.
Now when I try to call this method:
hit(playerCards, playerScore, playerSpacing);

Why is the playerScore and the playerSpacing not updating? The cards are being added just fine because they draw the respected Sprite, am I missing something?

A:

Java is always pass-by-value.  You are changing your local variables score and spacing, but those are copies of playerScore and playerSpacing.
But why did changes to cards update playerCards?  Because the object reference was passed by value.  You have a copy of the reference, which refers to the same object.  The object was changed (and can be changed through playerCards or cards).  If you had done cards = new Array<Card>();, then you would have given a new value to the local variable cards and playerCards would be unchanged when you change cards.

