Quantcast
Channel: uttumuttu
Viewing all articles
Browse latest Browse all 10

Static Checking is Defensive Programming

$
0
0
(But not vice versa.)

void openFridge(Object object) {
____if(!(object instanceof Fridge)) {
________throw new IllegalArgumentException("!(object instanceof Fridge)");
____} else {
________((Fridge) object).open();
____}
}


void openFridge(Fridge fridge) {
____if(fridge == null) {
________throw new IllegalArgumentException("fridge == null");
____} else {
________fridge.open();
____}
}

Viewing all articles
Browse latest Browse all 10

Trending Articles