I'm being forced to use the common anti-pattern of a public interface Constants which many classes in this project implement.  Long story short, I need to have a List constant which is pre-populated with values.  Normally I would do this like so:public static final List<String> MY_CONSTANT = new ArrayList<String>();static {    MY_CONSTANT.add(foo);    MY_CONSTANT.add(bar);    // ...}Unfortunately, I can't use static initializers in an interface.  So after much frustration, I finally have my implementation as follows:public static final List<String> MY_CONSTANT = new ArrayList<String>() {    private static final long serialVersionUID = 1898990046107150596L;    {        add(foo);        add(bar);        // ...    }}I hate the fact that I've made an anonymous extension like this and it makes me cringe.  Are there any better techniques I can use to accomplish this?  Changing the Constants file to a class instead of an interface isn't an option.  As I said, I'm just retouching a large, pre-existing code base.
Initializing complex constant in Constants interface
java
If you only need constant of java.util.List type you can use static method java.util.Arrays.asList:import static java.util.Arrays.asList;...public static final List<String> MY_CONSTANT = asList(foo, bar, baz);which creates immutable list instance with passed values.In cases when more complex object needs to be initialised I like to use static methods which create my constant:public static final SomeComplexObject constant = createMyConstant();private static SomeComplexObject createMyConstant() {    SomeComplexObject constant = new SomeComplexObject();    constant.setProp1(...);    constant.setProp2(...);    ...    return makeItSomehowImmutable(constant);}In your case you won't be able to declare private static method inside interface, so the only thing I find reasonable is to create separate utility class with static methods which create constants, declare your method there and reuse it just like with java.util.Arrays.asList method.Hope this helps...