Actually, static final variables can be overridden (see below), but I
was thinking of the case of someone wanting to extend a project with
some optional features might want to add more constants.  If they can
extend the current constants class, they don't have to differentiate (or
copy into their new constants class) between the base set and the
superset.  In other words, if I wanted to extend Shale without modifying
it, I might want to extend the ShaleConstants.

I've seen people provide private constructors for classes of static
methods, but I've never really understood why (since giving up C++,
anyway).

 - George


public class C1 {
    public static final String C1STRING = "C1";
    public static final String OVERRIDDEN = "no";
}

public class C2 extends C1 {
    public static final String C2STRING = "C2";
    public static final String OVERRIDDEN = "yes";
}

public class TestConstants extends TestCase {
    public void testThis() {
        assertEquals("C1", C2.C1STRING);
        assertEquals("no", C1.OVERRIDDEN);
        assertEquals("yes", C2.OVERRIDDEN);
    }
}

> -----Original Message-----
> From: James Holmes [mailto:[EMAIL PROTECTED] 
> Sent: Friday, June 10, 2005 2:53 PM
> To: 'Struts Developers List'
> Subject: RE: svn commit: r189997 - in 
> /struts/shale/trunk/core-library/src/java/org/apache/shale: 
> Constants.java faces/ShaleConstants.java
> 
> 
> Am I missing something or can static final variable values be 
> overridden?  I don't think they can and thus I don't see the 
> use case where you would extend a constants class.
> 
> James
> 
> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] 
> Sent: Friday, June 
> 10, 2005 1:42 PM
> To: [email protected]
> Subject: RE: svn commit: r189997 - in
> /struts/shale/trunk/core-library/src/java/org/apache/shale: 
> Constants.java faces/ShaleConstants.java
> 
>       [snip]   
> > +    /**
> > +     * <p>Private constructor so that this class cannot be
> > instantiated.</p>
> > +     */
> > +    private ShaleConstants() {}
> > +
> 
> Why would you want to do that?  This prevents someone from 
> extending the class with their own constants.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to