Card 09/ 09
All 9 cards
RecapDifficulty: Intermediate1 min
What the Variable Holds, and What the Type Guarantees
Five things this topic established, and where each one was.
| The thing | Where |
|---|---|
| A primitive variable holds the value; a reference variable holds an address | What a Variable Holds, and Why That Is Two Answers |
| Assignment copies what the variable holds, which is why two names can reach one list | Two Names for One Shopping Basket |
| Eight primitive types, each with a size and a default for fields | The Eight Types Everything Else Is Built From |
Money is never a double; it is pence in a long or a BigDecimal | int, long, double or BigDecimal |
| Widening is automatic, narrowing needs a cast, and the cast is you taking responsibility | Why the Compiler Refuses an Assignment You Have Not Run Yet |
The one worth carrying: the declared type is a promise checked before anything runs, and what the variable holds decides what assignment does. Those two facts between them answer most questions about why a value changed when you did not expect it to.