gpt4 book ai didi

java - 在静态嵌套类中定义常量

转载 作者:行者123 更新时间:2023-12-01 13:14:48 28 4
gpt4 key购买 nike

我正在静态嵌套类中定义常量

public final class Constants {

public static final class LDAP {
public static final String BASE_DN = "dc=example,dc=com";
public static final String OU = "ou";
public static final String CN = "cn";
public static final String SN = "sn";
public static final String GID_NUMBER = "gidNumber";
public static final String UID_NUMBER = "uidNumber";
public static final String HOME_DIRECTORY = "homeDirectory";
public static final String UID = "uid";
public static final String TELE_PHONE_NUMBER = "telephoneNumber";
public static final String USER_PASSWORD = "userPassword";

public static final String OBJECT_CLASS = "objectclass";
public static final String OBJECT_CLASS_TOP = "top";
public static final String OBJECT_CLASS_PERSON = "person";
public static final String OBJECT_CLASS_POSIX_ACCOUNT = "posixAccount";
}

public static final class GenericStringConstan {
public static final String EMAIL_REPLACE_CHAR_FROM = "@";
public static final String EMAIL_REPLACE_CHAR_TO = "__";
public static final String BACK_SLASH = "/";
public static final String FORWARD_SLASH = "/";

}

}

这是这样做的最佳实践吗?通过这个,我试图将所有常量分组到单个类中。
这些方法的优点和缺点是什么。
或者最好为不同类型的常量创建一个单独的类?

最佳答案

我不喜欢这种方法,因为你的类常量不再是包路径的一部分:

my.package.path.Constants.LDAP.UID

但仍然很难找到任何常量,因为文件可能很大。我会为每组常量/枚举创建一个不同的文件。

关于java - 在静态嵌套类中定义常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22557111/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com