/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) John D. Mitchell, 1996 -- All Rights Reserved PROJECT: JavaWorld MODULE: Tips & Tricks FILE: Constants2.java AUTHOR: John D. Mitchell, Mar 1, 1996 REVISION HISTORY: Name Date Description ---- ---- ----------- JDM 96.03.01 Initial version. DESCRIPTION: Use interface to define '#define' constants' equivalent. This file defines a Java Interface which contains a number of compile time constants. This file illustrates an alternative method for accessing the interface fields. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ interface ConstantsBase { public static final boolean DEBUG = false; public static final int GOLD_RECORDS = 10; public static final String BozoIdentity = "Homey"; } // This time we don't 'implement' the interface, we just access the // fields directly using the interface name qualification. public class Constants2 { public static void main (String args[]) { // Just access some of the constants. System.out.println ("GOLD_RECORDS = " + ConstantsBase.GOLD_RECORDS); System.out.println ("Bozo is really " + ConstantsBase.BozoIdentity); // If "DEBUG" is false, the compiler will collapse out the // entire guarded statement. if (ConstantsBase.DEBUG) System.out.println ("I'm here!!!"); } }