/** * This method should guarantee that if all callers accessing the resource using this method then the object is * returned atomically with respect to any validity state change. * * This is to avoid race conditions in cases where the state is changed when getting the resource. Some examples are * resources that can only be used a certain number of times. * * @return null if the object is not valid, otherwise the valid object */ default T getResourceIfValid() { if (isValid()) { return getResource(); } else { return null; } } }
/** * This method should guarantee that if all callers accessing the resource using this method then the object is * returned atomically with respect to any validity state change. * * This is to avoid race conditions in cases where the state is changed when getting the resource. Some examples are * resources that can only be used a certain number of times. * * @return null if the object is not valid, otherwise the valid object */ default T getResourceIfValid() { if (isValid()) { return getResource(); } else { return null; } } }