ParseUser getCurrentUser()无当前登录用户时返回值咨询
Looking at the provided Javadoc and implementation for ParseUser.getCurrentUser():
This retrieves the currently logged in ParseUser with a valid session, either from memory or disk if necessary.
@return The currently logged in ParseUser
The code implementation is:
/** * This retrieves the currently logged in ParseUser with a valid session, either from memory or * disk if necessary. * * @return The currently logged in ParseUser */ public static ParseUser getCurrentUser() { return getCurrentUser(isAutomaticUserEnabled()); }
The key point here is that while the Javadoc states it returns a logged-in ParseUser with a valid session, it does not explicitly specify what happens when there is no currently logged-in user (i.e., no valid session exists in memory or on disk).
In practice, this method will typically return null in that scenario, but since the official documentation doesn't call this out clearly, it's a good idea to handle the possibility of a null return value in your code to avoid unexpected NullPointerExceptions.
内容的提问来源于stack exchange,提问作者Adrian Buciuman

