示例

public interface ICommonParsingConstants {
public static final int IF_TOKEN = 1;
public static final int WHILE_TOKEN = 2;
public static final String END_OF_LINE = "\n"; //$NON-NLS-1$
}

public class Parser implements ICommonParsingConstants {
public void processToken( int iToken ) {
if ( iToken == IF_TOKEN ) {
System.out.println( "if" ); //$NON-NLS-1$
} else if ( iToken == WHILE_TOKEN ) {
System.out.println( "while" ); //$NON-NLS-1$
}
}
}

public class Tokenizer implements ICommonParsingConstants {
public String getToken( String str ) {
return ( END_OF_LINE.equals( str ) ? "" : str ); //$NON-NLS-1$
}
}

解决方案
  1. 将每个常量移动到其逻辑上所属的接口或类中。
  2. 除去空接口。

public class Parser {

public static final int IF_TOKEN = 1;
public static final int WHILE_TOKEN = 2;

public void processToken( int iToken ) {
if ( iToken == IF_TOKEN ) {
System.out.println( "if" ); //$NON-NLS-1$
} else if ( iToken == WHILE_TOKEN ) {
System.out.println( "while" ); //$NON-NLS-1$
}
}
}

public class Tokenizer {
public static final String END_OF_LINE = "\n"; //$NON-NLS-1$

public String getToken( String str ) {
return ( END_OF_LINE.equals( str ) ? "" : str ); //$NON-NLS-1$
}
}