Java编程中的访问控制与封装
1. 断言工具与包的使用
在Java编程里,我们可以借助改变导入的包,把代码从调试版本转变为生产版本。例如下面的断言工具代码:
public final static void is_true(boolean exp){}
public final static void is_false(boolean exp){}
public final static void
is_true(boolean exp, String msg) {}
public final static void
is_false(boolean exp, String msg) {}
若把之前的导入语句改为 import com.bruceeckel.tools.*; ,程序就不会再打印断言信息了。示例如下:
//: c05:TestAssert.java
// Demonstrating the assertion tool.
// Comment the following, and uncomment the
// subsequent line to change assertion behavior:
import com.bruceeckel.tools.debug.*;
// import com.bruceeckel.tools.*;
public class TestAssert {
public static void main(Str
订阅专栏 解锁全文
2397



被折叠的 条评论
为什么被折叠?



