Possible Duplicate:
Interfaces with static fields in java for sharing ‘constants’
We have constants that we need to use in lot of class and my question
is if its best practice to create interface with public attribute
or something else…
public static final String NAME = "Name";
Thanks!
– First of all answering you question in one breath…Yes its possible, infact if you use
public int x=5;Orint x=5,this will always be interpreted as
public static final int x=5;– But this is Not the Right way to do it.
– You can better use
EnumorClass with Private Constructorto handle this.Eg:
Class with a static field: