The _ () sign in Java is a kind of constructor

I am new to Java and started learning and learning a little about the language. Can anyone explain what is the meaning of _ () in this constructor. Is this a called constructor?

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);
    }
}

      

+3


source to share


2 answers


No, this is a very poorly named method. I am reminded of another similar question recently that cites some documentation that says that although the underscore alone is a legal name, it should not be used.



In this case, it appears that the class is Singleton

, and the method that is usually called is getInstance()

shortened to _()

.

+6


source


This is the fun design you are here for. function name "_".

So, you have something like UserRequestCache._()

that return UserRequestCache

.



Nothing to do with some strange Java magic

0


source







All Articles