Friday, April 20, 2007

Make sure you check for null!

When dealing with an object that could potentially be null, or some of its fields, don't just check the field for null, check the object first. Checking that a null object's field is not null will give you a Null Pointer Exception. Check the Object itself first!


When you hit a condition in a loop and you want to skip to the next item in the loop, don't use break; Use continue; break; gets you completely out of the loop. I knew that, but one stupid mistake like that could be the difference between the lunar module landing perfectly, or crashing in flames into a pile of moon dust!

No comments: