Java Tip #4: Switch comments

During testing, you often want to make things simpler. For example, if you want to test your new printing routines, you might want to see only the print preview instead of getting real printouts. You can switch between two code blocks by using the following pattern and by simply inserting or removing a single character:

//*
show_only_preview();
/*/
real_printing();
//*/

When removing the first slash, the second code block becomes active:

/*
show_only_preview();
/*/

real_printing();
//*/

One thought on “Java Tip #4: Switch comments

Leave a Reply

Your email address will not be published. Required fields are marked *