gpt4 book ai didi

java - 解释synchronized()内部的Commons Lang代码?

转载 作者:行者123 更新时间:2023-12-01 19:31:13 26 4
gpt4 key购买 nike

我正在尝试重写 JakartaCommons-lang 的一段代码,因为我们有一个包需要尽可能少的依赖项

static void unregister(Object value) {
Set registry = getRegistry();
if (registry != null) {
registry.remove(new IDKey(value));
synchronized(class$org$apache$commons$lang$builder$HashCodeBuilder == null ? (class$org$apache$commons$lang$builder$HashCodeBuilder = class$("org.apache.commons.lang.builder.HashCodeBuilder")) : class$org$apache$commons$lang$builder$HashCodeBuilder) {
registry = getRegistry();
if (registry != null && registry.isEmpty()) {
REGISTRY.set((Object)null);
}
}
}
}

有人可以解释一下synchronized()内部的代码吗?特别是所有 '$'

最佳答案

$ 是有效的标识符字符,因此它只是名称的一部分。

请注意,不鼓励使用 $。 Java 语言规范,第 3.8. Identifiers 部分说:

The "Java letters" include uppercase and lowercase ASCII Latin letters A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons, the ASCII dollar sign ($, or \u0024) and underscore (_, or \u005f). The dollar sign should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems. The underscore may be used in identifiers formed of two or more characters, but it cannot be used as a one-character identifier due to being a keyword.

如果使用 _ 来代替,对您来说会更具可读性吗?

synchronized (class_org_apache_commons_lang_builder_HashCodeBuilder == null ? (class_org_apache_commons_lang_builder_HashCodeBuilder = class_("org.apache.commons.lang.builder.HashCodeBuilder")) : class_org_apache_commons_lang_builder_HashCodeBuilder) {
...
}

或更短的名称?

synchronized (builderClass == null ? (builderClass = getClass("org.apache.commons.lang.builder.HashCodeBuilder")) : builderClass) {
...
}

关于java - 解释synchronized()内部的Commons Lang代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59726423/

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