I do a lot of null checking in my code, and usually I will check for not null before going on to my for or more if/else statements.
For example:
if(x!=null) {
for(int y:x) {
if(y.property1 != null) {
if( y.property < n) {
}
} else {
}
}
}
Is the following better practice?
if(x ==null) {
//exit or w/e you want to do
}
for(int y:x) {
if(y ==null){
}
if(y<0) {
}
}
Aucun commentaire:
Enregistrer un commentaire