class Gizmo {
public void spin() {}
} public class FinalArguments {
void with(final Gizmo g) {
//! g = new Gizmo(); // Illegal -- g is final
}
void without(Gizmo g) {
g = new Gizmo(); // OK -- g not final
g.spin();
}
// void f(final int i) { i++; } // Can't change
// You can only read from a final primitive:
int g(final int i) { return i + 1; }
public static void main(String[] args) {
FinalArguments bf = new FinalArguments();
bf.without(null);
bf.with(null);
}
}
上面的两句 bf.without(null);
bf.with(null);
它们与 bf.without();
bf.with();有什么不同???
一直没见过null可在实参中出现……
public void spin() {}
} public class FinalArguments {
void with(final Gizmo g) {
//! g = new Gizmo(); // Illegal -- g is final
}
void without(Gizmo g) {
g = new Gizmo(); // OK -- g not final
g.spin();
}
// void f(final int i) { i++; } // Can't change
// You can only read from a final primitive:
int g(final int i) { return i + 1; }
public static void main(String[] args) {
FinalArguments bf = new FinalArguments();
bf.without(null);
bf.with(null);
}
}
上面的两句 bf.without(null);
bf.with(null);
它们与 bf.without();
bf.with();有什么不同???
一直没见过null可在实参中出现……
void without(Gizmo g);//这个有参数...bf.without(null); 只是说g=null;
这种很常见嘛.
bf.with(null);调用有1个参的方法,null是所有元素的子元素