gpt4 book ai didi

java - _() 在 Java 中的意义是某种构造函数

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:43:58 26 4
gpt4 key购买 nike

我是 Java 的新手,开始学习和探索有关语言的一些知识。任何人都可以解释 _() 在该构造函数中的重要性。那叫构造函数吗?

public class UserRequestCache {

private final static ThreadLocal <UserRequest> t = new ThreadLocal <UserRequest>();

private static UserRequestCache instance = new UserRequestCache();

public static UserRequestCache _() {
return instance;
}

private UserRequestCache() {
}

public void checkPoint() {
if (logDebug()) {
if (getUserRequest() != null) {
logDebug(getUserRequest().toString());
}
}
}

public UserRequest getCache() {
// checkPoint();
return getUserRequest();
}

private UserRequest getUserRequest() {
return t.get();
}

public void setCache(UserRequest value) {
t.set(value);
}
}

最佳答案

不,这只是一个非常糟糕的命名方法。我记得最近另一个类似的问题,它引用了一些文档说即使单个下划线是合法名称,也不应该使用它。

在这种情况下,该类似乎是一个Singleton,通常名为getInstance() 的方法已缩短为_().

关于java - _() 在 Java 中的意义是某种构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29773488/

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