C구문의 전처리 구문인 #ifdef나 #ifndef같은 넘을 자바에서 사용하는 기본적인 내용이다. 아래처럼 println이 DEF가 정의되었냐 혹은 DEBUG모드냐에 따라 달라지는 형태로 되어 있는 구문인 경우
public class IFDef{ public IFDef(){ int i = 100; #ifdef DEF System.out.println("DEF"); #else System.out.println("not DEF"); #endif } }
아래처럼, 바꿔주면 된다.
private static final boolean def = false; if (def) { System.out.println("DEF"); } else { System.out.println("not DEF"); }