封装一个函数,将System.out.println(xx)封装成 print方法

1.工具类

package com.ld.staticUtil;

public class Print {

    private static boolean flag=true;

    public static void print(Object obj){
        if(flag) {
            System.out.print(obj);
        }
    }

}

2.测试类

package com.ld;

import java.math.BigInteger;
import static com.ld.staticUtil.Print.*;

public class Test9 {

    public static void main(String[] args) {
        BigInteger a = new BigInteger("-111",2);
        print(a);
    }

}

 

你可能感兴趣的:(Java)