Languageeasy0-2 years
When is var appropriate, and what are text blocks for?
var infers a local's type at compile time — use it when the type is visible on the line (new HashMap<...>()) or irrelevant to the reader; keep the explicit type when a method's return would leave the reader guessing. Text blocks are multi-line strings with indentation stripped, for SQL, JSON and HTML in code and tests.
PreviousHow do you read a stack trace with 90 framework frames in it?Next How do you make a class immutable, and why does it matter?
Is Java pass-by-value or pass-by-reference?What happens if you override equals() but not hashCode()?Why are strings immutable in Java, and what does that cost?What is the difference between int and Integer? Where does autoboxing bite?What changed in switch, and why should a sealed switch have no default?