While looking at the implementation of android LiveData, I stumbled on the following code snippet
public T getValue() {
Object data = mData;
if (data != NOT_SET) {
return (T) data;
}
return null;
}
Why would one assign a class member to a local variable before returning it? My guess is it is related to the fact that mData
is volatile
, but I can't fully understand why couldn't we just return mData
.