??????????У????????????????????????????洢???????????????????????????????????????????????????????????????????????????
???????????????????????????洢??Щ????????????????????????????????????????????????????????????????????????
??????y????磺
????package one;
????public interface Constants {
????String NAME="name1";
????int MAX_VAL=25;
????}
??????
????package two;
????public class Constants {
????public static final String NAME="name1";
????public static final int MAX_VAL=25;
????}
?????????????y?????????????????????????????????static???????????final???????????????Щ????′????????μ??????????????????????????????????
?????????????????????????????????????????????????209??????ubuntu 14.04???????????????????????????????366???????????????????????????????????ζ??????????????????????JVM ?????????????????????????????????????????????????????????????????
??????????????????????????????????????????????y???????泣????????а??????????????ú???????????????????
???????????????????????????????Щ???????????????????д???????????????????á??磺
????packagename.Constant.CONSTANT_NAME
????????????“????”??δ??????????????y??????????????????д“packagename.Constants”?????е???????????????
???????????????????y??????е?????????“???”????????е???????????????????????????????????????????????????????????????????????????????Java ?????????????????????????
??????????????????????????????final??????????????????????????????????????????е??????????????????????????????????????????????????????????????????б???????????????????t??????
???????ж??????????????????????
????package three;
????//make the class non-extendable by adding final ????final?????????????
????public final class Constants {
????//Hide the constructor ?????????
????private Constants(){}
????public static String NAME="name";
????}
?????????????????
????import static three.Constants.NAME;
????public class UseConstants {
????public static void main(String[] args) {
????System.out.println("the value of constants is"+NAME);
????}
????}
??????????????????????????????Constant Interface Anti-pattern????