Java?е????????α?????
???????????? ???????[ 2015/9/30 13:46:59 ] ??????????????
??????????У????????????????????????????洢???????????????????????????????????????????????????????????????????????????
???????????????????????????洢??Щ????????????????????????????????????????????????????????????????????????
??????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????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11