Where do you keep Constants used throughout your application?

前端 未结 5 1149
小蘑菇
小蘑菇 2021-02-05 03:59

Is interface an acceptable place to store my

public static final Foo bar

Do you extrapolate them to be read from outside of the program? Do you

5条回答
  •  无人共我
    2021-02-05 04:25

    If you are talking about a simple application the Constants class approach is fine:

    public class Constants {
        private Constants() {} // no way to instantiate this class
        public static final String MY_VAL = "123";
    }
    

    If you're building a larger app you should be using dependency injection, take a look at How can I inject a property value into a Spring Bean which was configured using annotations?

提交回复
热议问题