Declare constant
- Declare constant with a meaningful name to represent the string literal.
- Replace all occurences of the string literal with references to declared constant.
public static void main(String[] args) {
System.out.println( HELLO );
System.out.println( BYE );
System.out.println( HELLO );
}
private static final String HELLO = "Hello";
private static final String BYE = "Bye";
|
|