Hi everyone. I'm sure you'll all agree with me that interface field members are implicitly "public static final". But why is public static final transient allowed in a class whereas transient variables (read as public static final transient) are not:
Can somebody please spot the difference for me... Are static, final and transient really are allowable combinations for fields? [ March 19, 2004: Message edited by: nikki lorenzo ]
Every field declaration in the body of an interface is implicitly public, static, and final. It is permitted to redundantly specify any or all of these modifiers for such fields.
As you can see from this, all fields declared within an Interface are implicitly public, static, and final, but they are not allowed to be transient. In addition, I think it's more important to realize what these modifiers mean as that will help you remember when and where you can (and should) use them. For example, what does transient mean? The keyword transient indicates that this piece of data is not part of the persistent state of an object. Because you can never have an instance of an Interface, what sense does it make for a variable to be decalred transient within an Interface. So, in short, the difference is that one variable is declared within a class (which can be serialized and therefore the transient keyword makes sense) while the other is declared within an Interface, where the keyword makes no sense. I hope that helps, Corey