Robert

62%
Flag icon
null;
Robert
Bad pattern here: initializing a variable (to null) that can only ever be accessed after being (re)assigned. I recommend starting by not assigning a default value. That will help ensure every path results in a value, and it's clearer to future developers that why (what conditions) results in null (or whatever default value), if any (often time all paths result in a value, and the default — which was misleading — is discarded).
Brian
· Flag
Brian
forgot: java compiler will barf if accessed before initialized?
Robert
· Flag
Robert
yup! (better yet, your IDE should tell you long before you try to compile 😉)
Effective Java: A Programming Language Guide (Java Series)
Rate this book
Clear rating
Open Preview