devxlogo

Eliminate the Need to Comment/Remove Debug Statements

Eliminate the Need to Comment/Remove Debug Statements

Often, while developing a system, you need to put a lot of debug statements in the code, all which have to be commented/removed before delivering the application. There’s a class with a static method that can be used to turn on/off debug statements without having to comment them or remove them. Here it is:

 class MyDebug{    private static boolean bDEBUG = true;    public static void printDebug(String s){        if(bDEBUG){            System.out.println(s);        }    }

To print a debug statement, a call to MyDebug.printDebug(s) is all that is needed. To turn off debug statements, just change the bDEBUG static variable to false and recompile the application.

devx-admin

Share the Post: